Conversion of Mathematica code to matlab
Mostrar comentarios más antiguos
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++]
2 comentarios
Walter Roberson
el 4 de Mzo. de 2013
Is f defined in terms of "a" ?
Mikhos
el 4 de Mzo. de 2013
Respuestas (2)
Walter Roberson
el 4 de Mzo. de 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 comentarios
Mikhos
el 11 de Mzo. de 2013
Mikhos
el 11 de Mzo. de 2013
Walter Roberson
el 11 de Mzo. de 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
el 12 de Mzo. de 2013
Walter Roberson
el 12 de Mzo. de 2013
Please show your current coding
Mikhos
el 12 de Mzo. de 2013
Walter Roberson
el 12 de Mzo. de 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
el 12 de Mzo. de 2013
Walter Roberson
el 12 de Mzo. de 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
el 12 de Mzo. de 2013
Walter Roberson
el 12 de Mzo. de 2013
Why did you remove the ",v" in the argument lists?
Mikhos
el 13 de Mzo. de 2013
ABHIJAY PANDEY
el 6 de Sept. de 2016
0 votos
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.
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!