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
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에 대해 자세히 알아보기

질문:

2015년 11월 13일

편집:

2015년 11월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by