Conversion of Mathematica code to matlab
Show older comments
I have the following code in mathematical and need to convert it into matlab but cant for the life of me understand ow to do it, though i think i need to use the 'fzero'; command. Please could someone help me or give me a hint?
function 'f' has already been defined but i need to find its roots for where variable a is from 0-0.6 etc
list1=For[a=-0.01, a<0.6, a+=0.01; sol=Findroot[f,{u, 1.00,1.10}];
v1[i] = sol[[1,2]]; i++]
Answers (2)
Walter Roberson
on 4 Mar 2013
vl = arrayfun(@(a) fzero( @(x) f(x,a), [1 1.1] ), -0.01 : 0.01 : 0.6-eps);
the "-eps" is to recreate the "<" part of "<0.6". Using 0.5 instead might work.
12 Comments
Mikhos
on 11 Mar 2013
Mikhos
on 11 Mar 2013
Walter Roberson
on 11 Mar 2013
Your original question implies that f is a function of both "a" and "u", but you have no "u" in your f. It appears though that you have an unresolved symbol "v" hovering around.
What purpose is your "epsilon" function? You do not use it. Perhaps in your definition of f, you meant to use epsilon(a) instead of eps(a) ?
Mikhos
on 12 Mar 2013
Walter Roberson
on 12 Mar 2013
Please show your current coding
Mikhos
on 12 Mar 2013
Walter Roberson
on 12 Mar 2013
w =0.001;
g = @(a, v) (2048*((1+v).^4) + 128*((1+v).^2).*a.^6 + a.^12 + 16*(1+v).*sqrt(16384*((1+v).^6) + 2048*((1+v).^4).*a.^6 + 80*((1+v).^2).*a.^12 + a.^18)).^(1/3);
r =@(a, v) (1/(16*(1+v))).*( a.^4 + (a.^8)./g(a, v) + g(a, v) );
alpha= @(a, v) (a./r(a, v));
A= @(a, v) 2*pi*(r(a, v).^2)*(1+sqrt(1-alpha(a, v).^2));
epsilon = @(a, v) 1/2*(A(a, v)/(4*pi-pi*a.^2)-1);
f= @(a, v) (1-sqrt(1-alpha(a, v).^2)).*epsilon(a, v) + (epsilon(a, v).^2) - w == 0;
vl = arrayfun(@(a) fzero( @(v) f(a,v), [1 1.1] ), -0.01 : 0.01 : 0.6-eps);
I think.
Mikhos
on 12 Mar 2013
Walter Roberson
on 12 Mar 2013
Yup. The first part of your expression for f is producing a non-zero value, and the second part compares that non-zero value to 0, producing a logical false, and logic false has numeric value 0, so when fzero() is looking for a location that makes the function 0, it finds it first time around. Not sure why you would want the "== 0" in there...
If you remove the "== 0" and investigate a whole bunch, you will find that your expression has no real roots for that range of "a" within the interval [1 1.1]
Mikhos
on 12 Mar 2013
Walter Roberson
on 12 Mar 2013
Why did you remove the ",v" in the argument lists?
Mikhos
on 13 Mar 2013
ABHIJAY PANDEY
on 6 Sep 2016
0 votes
f[x_]=0.09*sin[x]+0.085*sin[x-1] plot[f[x],{x,-2,2}] can anybody please tell me the matlab code for this mathematica code.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!