Error solving transcendental function
Show older comments
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
on 13 Nov 2015
0 votes
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 MATLAB 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!