MATLAB Answers

Jason
0

Writing this Mathcad equation in Matlab

Asked by Jason
on 22 Mar 2018
Latest activity Commented on by Star Strider
on 23 Mar 2018
hi, Im trying to convert an equation from mathcad into matlab but am struggling. the equation is:

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 22 Mar 2018
 Accepted Answer

Try this:
psi = 0.142;
Io = 1;
f_vir2 = @(r) 4*Io * abs(integral(@(rho)besselj(0, pi*rho*r*psi).*rho, 0, 1)).^2;
r = pi;
test_call = f_vir2(r)

  8 Comments

Torsten
on 23 Mar 2018
You call "f_vir" with an array of values for r, "integral" usually calls "f_vir" with an array of values for rho. This would usually make multiplications of the form "r*rho" within "f_vir" incompatible. To avoid this conflict in lengths, the "ArrayValued=true" option tells "integral" to call "f_vir" only with a single scalar for "rho".
You could also use
r=linspace(-20,20);
for i=1:numel(r)
f_vir_array(i)=f_vir(r(i));
end
plot(r,f_vir_array)
without the "ArrayValued=true" option.
Best wishes
Torsten.
Thankyou again
@Torsten — Thank you.
@Jason — Our pleasure.

Sign in to comment.