Clear Filters
Clear Filters

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

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2017
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 Comment
Walter Roberson
Walter Roberson on 7 Jun 2017
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!