Error solving transcendental function

2 views (last 30 days)
Aaron Pacheco
Aaron Pacheco on 13 Nov 2015
Edited: Walter Roberson on 14 Nov 2015
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!

Answers (1)

Steven Lord
Steven Lord on 13 Nov 2015
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!