ecc= 0.1
M= linspace(0, 2*pi, 800);
%%solving for psi using fzero
f = @(psi) psi- ecc*sin(psi)- M;
psi = zeros(size(M));
for j = 1:length (M)
psi(j)=fzero(f,1);
end
The original equaions is M = ψ - epsilon* sin ψ, trying to solve psi(M) for each M entry.
Could someone spot the errors in this? When I run the program, it show erros in fzero , "operands to the || and && operators ust be convertible to logical scalar values. Errors in fzero (line 307) else if ~ isfinite(fx) || ~isreal f(x)

답변 (1개)

DGM
DGM 2021년 4월 1일
편집: DGM 2021년 4월 1일

0 개 추천

Your problem is with how you set up your function. Your parameter M is a vector in the function definition, so at any given point, the function returns a vector. f(x) should return a scalar, not a vector. What your loop implies is that you're looking to find the root given M(j), so just do that.
ecc= 0.1
M= linspace(0, 2*pi, 800);
%%solving for psi using fzero
psi = zeros(size(M));
for j = 1:length (M)
f = @(psi) psi- ecc*sin(psi)- M(j);
psi(j)=fzero(f,1);
end
psi

카테고리

도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

질문:

2021년 4월 1일

편집:

DGM
2021년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by