Effacer les filtres
Effacer les filtres

Matlab is not plotting anything

1 vue (au cours des 30 derniers jours)
Mohammed
Mohammed le 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

Réponses (2)

Chad Greene
Chad Greene le 6 Mar 2013
Modifié(e) : Chad Greene le 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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by