Matlab is not plotting anything

1 次查看(过去 30 天)
Mohammed
Mohammed 2013-3-6
Hi I'm working on a hw problem and I got the correct answers but the matlab is not plotting anything here is my code
for N = (5:5:85)
r = 0.15;
l = 50000;
p = [r * l * (1 + r/12)^(12 .* N )/ (12 * ((1+r/12)^(12 .* N) - 1 ))];
x = [N(1): N(end)];
y = [p(1) : p(end)];
disp( [ N p]);
plot(N,p)
format bank
end

回答(2 个)

Chad Greene
Chad Greene 2013-3-6
编辑:Chad Greene 2013-3-6
Matlab is plotting something--only the last value in the loop. To get the results with a loop, I suggest this solution:
N = (5:5:85);
p = NaN(size(N)); % preallocate to speed things up
for n = 1:length(N)
r = 0.15;
l = 50000;
p(n) = [r * l * (1 + r/12)^(12 .* N(n) )/ (12 * ((1+r/12)^(12 .* N(n)) - 1 ))];
% x = [N(1): N(end)];
% y = [p(1) : p(end)];
% disp( [ N p]);
format bank
end
plot(N,p)
However, I think the loop is unnecessary (loops tend to slow things down). I'd prefer this simpler solution instead:
N = (5:5:85);
r = 0.15;
l = 50000;
p = r * l * (1 + r/12).^(12 .* N )./ (12 * ((1+r/12).^(12 .* N) - 1 ));
plot(N,p,'r')

vijayasinthujan vijayaratnam
clear all clc
N = (5:5:85);
r = 0.15;
l = 5000;
p = [r * l * (1 + r/12).^(12 .* N )./ (12 * ((1+r./12).^(12 .* N) - 1 ))];
x = [N(1): N(end)]; y = [p(1) : p(end)]; disp( [ N, p]) plot(N,p) format bank

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by