## Writing this Mathcad equation in Matlab

### Jason (view profile)

on 22 Mar 2018
Latest activity Commented on by Star Strider

on 23 Mar 2018

### Star Strider (view profile)

hi, Im trying to convert an equation from mathcad into matlab but am struggling. the equation is:

### Star Strider (view profile)

on 22 Mar 2018

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)

Torsten

### Torsten (view profile)

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.
Jason

on 23 Mar 2018
Thankyou again
Star Strider

### Star Strider (view profile)

on 23 Mar 2018
@Torsten — Thank you.
@Jason — Our pleasure.