Why don't graphics appear for this code?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Why don't graphics appear for this code?
% Variáveis
m = 112.34;
temp = 25;
ISC = 7.8;
VTR = 0.0257;
VT = 0.0257;
VCA = 32.7;
GR = 1000;
G = 700;
% Cálculo do IR
IR = 1000 * (ISC / (2.718*exp(VCA/(m*VTR))-1))
for V = 0:1:VCA
V1 = V*2
%Carcular a potencia máxima para G=1000
P = V1*IR*35
end
figure(1)
h=plot(V1,P);
set(h,'color',rand(1,3),'linewidth',2);
hold on
axis([0 200 0 40])
xlabel('Tensão')
ylabel('Potência')
title('Curva P-V')
0 comentarios
Respuesta aceptada
Walter Roberson
el 15 de Mzo. de 2011
Each time through the loop you replace V1 and P, so at the end of the loop you only have a single point to plot.
Try
V1 = (0:1:VCA).*2; P = V1.*IR.*35;
with no loop.
0 comentarios
Más respuestas (3)
Nuno
el 15 de Mzo. de 2011
2 comentarios
Walter Roberson
el 15 de Mzo. de 2011
You _can_ do it with a loop, provided that you store the V1 and P value that results from each loop. You aren't doing that now: each time through the loop, you are overwriting the previously calculated value.
Matt Tearle
el 15 de Mzo. de 2011
What Walter was saying above is that you don't *need* to have a loop -- his solution does the same thing, cleaner and simpler.
As an aside, note that 0:1:VCA will give you whole numbers from 0 up to 32, because VCA is 32.7. That is, the range operator in MATLAB is essentially "<=". Obviously I don't know your intention -- just wanted to make sure you're aware of that.
Nuno
el 15 de Mzo. de 2011
2 comentarios
Walter Roberson
el 15 de Mzo. de 2011
Notice I used
V1 = (0:1:VCA).*2
But even without the multiplication by 2, I do not find any obvious error in P=V1.*IR.*35 . What error do you observe?
Matt Tearle
el 15 de Mzo. de 2011
Works fine for me:
m = 112.34;
temp = 25;
ISC = 7.8;
VTR = 0.0257;
VT = 0.0257;
VCA = 32.7;
GR = 1000;
G = 700;
% Cálculo do IR
IR = 1000 * (ISC / (2.718*exp(VCA/(m*VTR))-1));
V = 0:1:VCA;
V1 = V*2;
%Carcular a potencia máxima para G=1000
P = V1*IR*35;
figure(1)
h=plot(V1,P);
set(h,'color',rand(1,3),'linewidth',2);
hold on
axis([0 200 0 40])
xlabel('Tensão')
ylabel('Potência')
title('Curva P-V')
Nuno
el 15 de Mzo. de 2011
7 comentarios
Matt Tearle
el 16 de Mzo. de 2011
And, more importantly, correct. 2.718^x is an inaccurate version of exp(x).
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!