필터 지우기
필터 지우기

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