No values in plot?

2 visualizaciones (últimos 30 días)
hag12899
hag12899 el 24 de Sept. de 2020
Respondida: David Hill el 24 de Sept. de 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');

Respuestas (1)

David Hill
David Hill el 24 de Sept. de 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');

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by