Clear Filters
Clear Filters

Matlab is not plotting anything

1 view (last 30 days)
Mohammed
Mohammed on 6 Mar 2013
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

Answers (2)

Chad Greene
Chad Greene on 6 Mar 2013
Edited: Chad Greene on 6 Mar 2013
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

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!