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!