Why am I getting unexpectedly large numbers in calculations in MATLAB?

3 次查看(过去 30 天)
Hi all,
I am trying to perform some operations using Bessel function and plot 'v' against 'r' (as defined in the adjacent image).
But when I am defining the function 'F' (from image) and evaluating it at certain points (which are roots of J2), I am getting unexpectedly large numbers and MATLAB is not performing simple mathematical operations on them on it's own.
My program for this is:
bessj2 = inline('besselj(2,x)');
for n = 1:10
z(n) = fzero(bessj2,[(n-1) n]*pi);
end
z(1)=[];
syms x;
F1=diff(besselj(1,x),x);
f1=besselj(0, z) - besselj(1, z)/z;
syms r t;
F=@(x,t)besselj(1,x).*(exp(x.*x*t/100)-1)./(x.*x);
f=eval(subs(F,x,z));
F2=besselj(1,z).*(1./z-1)./z;
F3=@(x,r,t)(besselj(1,x.*r).*exp(-x.*x*t./100).*(f+F2))./(f1.^2);
f3=eval(subs(F3,x,z));
f4=sum(f3);
v=@(r,t)2*f4;
ezplot(v,[0,1,0,10])
Please help me figure out a way to solve this problem.
Thank you.

采纳的回答

Walter Roberson
Walter Roberson 2017-6-7
Never eval() a symbolic expression. Symbolic expressions are in a language that is not MATLAB.
You need to symfun to construct your v. Your existing code for v ignores the inputs. When you name a dummy parameter in an anonymous function definition @(r,t) but do not use the parameter in the text of the anonymous function, then that does not bind to any symbolic variable you might happen to have with the same name.
  1 个评论
Walter Roberson
Walter Roberson 2017-6-7
Or instead of symfun use matlabFunction with the 'vars' parameter to allow you to control the order of the inputs to the anonymous function created.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by