Clear Filters
Clear Filters

How to do summation and integration?

6 views (last 30 days)
Athira T Das
Athira T Das on 29 Apr 2023
Edited: Walter Roberson on 29 Apr 2023
clc;close all;clear all
syms r ph phi z
m=1
m = 1
lam=532 *10^-9;
k=2*pi/lam;
omega=30;
w0=0.002;rho=1;p=1;R=0.06;
N=3
N = 3
for h=-N:1:N
E1 = 1./(w0^2) + (1i*k)./(2*z);
Con11=(1i./(2.*lam.*z)).*exp((omega.^2./2 + r.^2 + omega)./E1).*exp((-1i.*k.*r.^2)./(2.*z)).*(pi./E1).*(1./(2.*1i.*sqrt(E1))).^m;
Con21=(1i./(2.*lam.*z)).*exp((omega.^2./2 + r.^2 + omega)./conj(E1)).*exp((-1i.*k.*r.^2)./(2.*z)).*(pi./conj(E1)).*(1./(2.*1i.*sqrt(conj(E1)))).^m;
for s=0:m
E01 = Con11.*((exp(-r.*(cos(ph)+sin(ph))).*hermiteH(s,1i*(omega./2 - r*cos(ph))./sqrt(E1)).*hermiteH(m-s,1i*(omega./2 - r*sin(ph))./sqrt(E1))) - (exp(r.*(cos(ph)+sin(ph))).*hermiteH(s,-1i*(omega./2 + r*cos(ph))./sqrt(E1)).*hermiteH(m-s,-1i*(omega./2 + r*sin(ph))./sqrt(E1))));
E0s1 = Con21.*((exp(-r.*(cos(phi)+sin(phi))).*hermiteH(s,1i*(omega./2 - r*cos(phi))./sqrt(conj(E1))).*hermiteH(m-s,1i*(omega./2 - r*sin(phi))./sqrt(conj(E1)))) - (exp(r.*(cos(phi)+sin(phi))).*hermiteH(s,-1i*(omega./2 + r.*cos(phi))./sqrt(conj(E1))).*hermiteH(m-s,-1i*(omega./2 + r*sin(phi))./sqrt(conj(E1)))));
Q = ((1i*p).^(m-s)).*nchoosek(m,s).*E01.*E0s1.*exp(-1i.*(h-m).*(ph-phi)).*exp((-2.^(5/6)).*(r.^(5/3)).*((1-cos(phi-ph)).^(5/6)).*(rho.^(-5/3)));
end
q = Q.*r;
fun = matlabFunction(q,'Vars',[ph,phi,r,z]);
z=linspace(0.01,10);
R = abs(arrayfun(@(z)integral3(@(ph,phi,r)fun(ph,phi,r,z),0,2*pi,0,2*pi,0,R),z));
end
Error using sym/matlabFunction>checkVars
Variable names must be valid MATLAB variable names.

Error in sym/matlabFunction (line 158)
vars = checkVars(funvars,opts);
R

Answers (1)

Walter Roberson
Walter Roberson on 29 Apr 2023
Edited: Walter Roberson on 29 Apr 2023
fun = matlabFunction(q,'Vars',[ph,phi,r,z]);
z=linspace(0.01,10);
That is within a loop. The first time sym z is in effect but immediately after you replace z with numeric z. The second time through z is no longer symbolic and so cannot be used in 'Vars'

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!