Double integration in matlab

6 views (last 30 days)
AVM
AVM on 5 Mar 2020
Commented: AVM on 5 Mar 2020
I would like to double integrate the following code, but some error is happenig. Pl somebody help me.
clc;
clear;
syms r1 theta1 n1 m1
r2=1.0;
theta2=2.0;
alpha1=0.5;
alpha2=1.0;
lambda=2.0;
omega=1;
phi=pi/3;
mu=cosh(r2);
nu=exp(1i*theta2).*sinh(r2);
beta1=r1.*exp(1i*theta1);
f1=exp(-((alpha1).^2)-((alpha2).^2)-((abs(beta1)).^2)-(1/mu).*real(((alpha2).^2)*conj(nu)));
f2=@(n1,m1)(((alpha1*conj(beta1))^(n1))./factorial(n1))*(((conj(alpha1)*(beta1))^(m1))/factorial(m1));
f3=1./sqrt((((mu).^2)-(abs(nu)).^2));
f4= exp((((1/mu).*real(((alpha2).^2)*conj(nu)))+(((alpha2).^2)))./((((mu).^2)-(abs(nu)).^2)));
Q1=(1/pi)*f1.*f3.*f4.*symsum(symsum(f2,n1,0,20),m1,0,20);
a1=@(r1,theta1)(1/2).*((beta1).*exp(-1i*phi)+conj(beta1).*exp(1i*phi)).*Q1;
a2=@(r1,theta1)(1/4)*(((beta1).^2)*exp(-2*1i*phi)+((conj(beta1)).^2)*exp(2*1i*phi)+(2*(abs(beta1)).^2)-1).*Q1;
x1=integral2(a1,0,10,0,2*pi)
x2=integral2(a2,0,10,0,2*pi)
Error using integral2Calc>integral2t/tensor (line 231)
Input function must return 'double' or 'single' values. Found 'sym'.

Answers (1)

Steven Lord
Steven Lord on 5 Mar 2020
Dont use integral or integral2 to integrate a symbolic function. Use one of the symbolic integration functions listed on this documentation page or use the matlabFunction function to create a numeric function suitable for use with integral or integral2 as per the examples on this documentation page.
  1 Comment
AVM
AVM on 5 Mar 2020
Thanks. Then can I use
int(int(fun,r1,0,10),theta1,0,2*pi) % for double integration?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!