Error solving transcendental function
古いコメントを表示
E-e*sin(E)-M=0
I'm attempting to solve this equation for E and plot E vs. M (varying from 0 to 2pi) while e=[0:0.25:1]
Here's my code:
function output=kepler(M,e)
M=[0:(2*pi)/4:2*pi]
e=[0:0.25:1]
n=0
while n<length(e)
n=n+1
m=0
while m<length(M)
m=m+1
Eroot(M,e)=fzero(@(E)(E-e*sin(E)-M),M(m))
end
end
Here are the errors I get:
Operands to the || and && operators must be
convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)
Error in kepler (line 14)
Eroot(M,e)=fzero(@(E)(E-e*sin(E)-M),M(m))
I know I haven't even attempted to plot my answers yet but I really need to solve for E first and am really struggling.
HELP!
回答 (1 件)
Steven Lord
2015 年 11 月 13 日
0 投票
FZERO solves one equation in one unknown. By using vectors e and M in the anonymous function you pass into FZERO, you're essentially giving it many equations in one unknown.
Even if you solve this by using loops over e and M and solving for each individual element of e and M you're going to run into a problem. Both e and M contain values that are unsuitable to use as matrix indices, but you're using them as indices into Eroot. You will need to fix that.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!