No values in plot?

1 vue (au cours des 30 derniers jours)
hag12899
hag12899 le 24 Sep 2020
Here's the following code I've written to make a plot that is equal to the inverse of mathematical constant e (e). I can't quite figure out why my plot is completely empty when I open it, so I'm thinking I'm missing something somewhere. Any suggestions on what I need to do to get the right plot?
clear;
counter=1;
for i=1:50
My_numb_1=i;
My_numb_2=abs(1./My_numb_1);
My_numb_3=abs(1-My_numb_2);
My_numb_4=abs(My_numb_3.^i);
end
% plot of error vs n
x=counter;
y=My_numb_4;
plot(x,y)
grid on;
title('error vs. n');
xlabel('n');
ylabel('error');

Réponses (1)

David Hill
David Hill le 24 Sep 2020
Not sure what you were doing, but each loop iteration you were overriding your data. No loop needed.
My_numb_1=1:50;
My_numb_2=1./My_numb_1;
My_numb_3=1-My_numb_2;
My_numb_4=My_numb_3.^My_numb_1;
plot(My_numb_1,My_numb_4);
grid on;
title('error vs. n');
xlabel('n');
ylabel('error');

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by