Conversion of Mathematica code to matlab
古いコメントを表示
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 件)
Walter Roberson
2013 年 3 月 4 日
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 件のコメント
Mikhos
2013 年 3 月 11 日
Mikhos
2013 年 3 月 11 日
Walter Roberson
2013 年 3 月 11 日
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
2013 年 3 月 12 日
Walter Roberson
2013 年 3 月 12 日
Please show your current coding
Mikhos
2013 年 3 月 12 日
Walter Roberson
2013 年 3 月 12 日
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
2013 年 3 月 12 日
Walter Roberson
2013 年 3 月 12 日
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
2013 年 3 月 12 日
Walter Roberson
2013 年 3 月 12 日
Why did you remove the ",v" in the argument lists?
Mikhos
2013 年 3 月 13 日
ABHIJAY PANDEY
2016 年 9 月 6 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!