Code not showing any result or any error

1 view (last 30 days)
Tushar Das
Tushar Das on 28 May 2023
Answered: Walter Roberson on 28 May 2023
clc
clear all
close all
e = 0.1;
M_min = 0;
M_max = 2 * pi;
N = 20;
function [E, M] = kepler_plot(e, M_min, M_max, N)
f = @(E) E - e * sin(E) - M;
M = linspace(M_min, M_max, N);
E = fzero(f, 0, M);
plot(M, E)
xlabel('Mean Anomaly')
ylabel('Eccentric Anomaly')
title('Keplers Equation')
end
this is the code. matlab is not showing any error or any result.

Answers (1)

Walter Roberson
Walter Roberson on 28 May 2023
Your code defines kepler_plot but never invokes it.
But you have other problems as well. I had to guess what you were doing.
e = 0.1;
M_min = 0;
M_max = 2 * pi;
N = 20;
[E, M] = kepler_plot(e, M_min, M_max, N)
E = 1×20
0 0.3665 0.7279 1.0803 1.4217 1.7518 2.0719 2.3836 2.6893 2.9912 3.2920 3.5939 3.8996 4.2113 4.5313 4.8615 5.2029 5.5553 5.9167 6.2832
M = 1×20
0 0.3307 0.6614 0.9921 1.3228 1.6535 1.9842 2.3149 2.6456 2.9762 3.3069 3.6376 3.9683 4.2990 4.6297 4.9604 5.2911 5.6218 5.9525 6.2832
function [E, M] = kepler_plot(e, M_min, M_max, N)
f = @(E,m) E - e * sin(E) - m;
M = linspace(M_min, M_max, N);
E = arrayfun(@(m) fzero(@(E)f(E,m), 0), M);
plot(M, E)
xlabel('Mean Anomaly')
ylabel('Eccentric Anomaly')
title('Keplers Equation')
end

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!