Why don't graphics appear for this code?

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')

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 15일

2 개 추천

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.

추가 답변 (3개)

Nuno
Nuno 2011년 3월 15일

0 개 추천

Why i can´t make loop?

댓글 수: 2

Walter Roberson
Walter Roberson 2011년 3월 15일
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
Matt Tearle 2011년 3월 15일
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
Nuno 2011년 3월 15일

0 개 추천

But if i change to V1= 0:0.1:VCA appear error in P=V1.*IR.*35...

댓글 수: 2

Walter Roberson
Walter Roberson 2011년 3월 15일
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
Matt Tearle 2011년 3월 15일
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
Nuno 2011년 3월 15일

0 개 추천

Yes, the code works... Thanks! But now i have a new problem...
When i complile de program, the graphs should give a value of voltage (V) up to 32,7 but the value is ~12,5. Why?
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));
V1 = (0:0.1:VCA);
ICC = ISC * (G/GR);
I = ICC - IR.*(2.718.*exp(V1./(m.*VT))-1);
ICC1 = ISC * ((G+100)/GR);
I1 = ICC1 - IR.*(2.718.*exp(V1./(m.*VT))-1);
ICC2 = ISC * ((G+200)/GR);
I2 = ICC2 - IR.*(2.718.*exp(V1./(m.*VT))-1);
ICC3 = ISC * ((G+300)/GR);
I3 = ICC3 - IR.*(2.718.*exp(V1./(m*VT))-1);
ICC4 = ISC * ((G+400)/GR);
I4 = ICC4 - IR.*(2.718.*exp(V1./(m*VT))-1);
%Carcular a potencia máxima para G=1000
P = V1.*I3;
figure(1)
j=plot(V1,P);
set(j,'color',rand(1,3),'linewidth',2);
hold on
axis([0 40 0 100])
xlabel('Tensão(V)')
ylabel('Potência')
title('Curva P-V')
figure(2)
h=plot(V1,I,V1,I1,V1,I2,V1,I3,V1,I4);
set(h,'color',rand(1,3),'linewidth',2);
hold on
axis([0 40 0 40])
xlabel('Tensão(V)')
ylabel('Corrente')
title('Curva I-V')

댓글 수: 7

Walter Roberson
Walter Roberson 2011년 3월 15일
The voltage does go up to there, but the axis() call forces all output values below 0 to be discarded.
I do not know what is being calculated (and would not necessarily understand it if you explained).
Question: why are you multiplying those values by 2.718 ? Isn't that just exp(1) ? So why not just add 1 to the value inside the exp() and not do the multiplication?
Nuno
Nuno 2011년 3월 15일
I calculate the diode current in a photovoltaic circuit.
2.718 is a nepper number and exp() is exponensial...
I can review the calculations...
Walter Roberson
Walter Roberson 2011년 3월 15일
The nepper number that is approximately 2.718 *is* exactly exp(1) .
Nuno
Nuno 2011년 3월 15일
Ok... Stupid error :(
But gives error if i change to: I = ICC - IR.*(2.718^(V1./(m.*VT))-1);
Walter Roberson
Walter Roberson 2011년 3월 15일
Use .^ instead of ^
Also, exp(expression) would be clearer than 2.718.^(expression)
Matt Tearle
Matt Tearle 2011년 3월 16일
And, more importantly, correct. 2.718^x is an inaccurate version of exp(x).
Nuno
Nuno 2011년 3월 16일
The error is in another count... Thanks for the help...

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2011년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by