Troubles with plotting two functions in one graph

I am having troubles with the following code:
function polarisatiecurve
P = 100
I = 0:0.0001:200;
U1 = P/I;
U2 = 800*(I+19)^2 - 2*(I+19)^3;
plot(I,U1,'b',I,U2,'r',[0,100,0,600]);
subplot (1,2,1);
xlabel('Stroom (A)')
ylabel('Spanning (V)')
title('Polarisatiecurve')
axis([0 120 0 4000])
grid on
grid on
end
What I want to do is plot two functions in one graph. The terms 'polarisatiecurve, stroom, spanning' are Dutch and mean polarisation curve, current (stroom) and voltage (spanning). What I want is that it plots two functions in the same graph. Both functions depend on the current I (the 'stroom'). However I can't get it to work. It gave me the following error:
Error using / Matrix dimensions must agree.
Error in polarisatiecurve (line 4) U1 = P/I;
That refers to the following line of code:
I tried converting I to a symbolic expression but that didn't work either. Who knows how to fix it?

 채택된 답변

Amit
Amit 2014년 1월 16일
편집: Amit 2014년 1월 16일
Few errors: like U1 = P/I. This is invalid operation as I is a matrix. To do this you use '.' operator. Similarly for ^, you will use .^ instead for the operations for matrixes.
function polarisatiecurve
P = 100;
I = 0:0.0001:200;
U1 = P./I;
U2 = 800*(I+19).^2 - 2*(I+19).^3;
plot(I,U1,'b',I,U2,'r'); %,[0,100,0,600]);
%subplot (1,2,1);
xlabel('Stroom (A)')
ylabel('Spanning (V)')
title('Polarisatiecurve')
%axis([0 120 0 4000])
grid on
grid on
end

댓글 수: 3

N/A
N/A 2014년 1월 16일
편집: N/A 2014년 1월 16일
Thanks but that gave me a new problem I just can't wrap my head around. It shows the the lines the wrong way.
I currently have it this way:
function polarisatiecurve
P = 100;
I = 0:1:30;
U1 = P./I;
U2 = 20*I.^2 - 2*I.^3;
plot(I,U1);
xlabel('Stroom (A)')
ylabel('Spanning (V)')
title('Polarisatiecurve')
grid on
end
That gives me a nice plot of a 100/I= U1. That works. I see everything I need. Now I have the function But when I want to plot U2 in the same graph, it changes the window automatically. And now I can't see anything interesting (I can't see the points where they intersect. What is going on?
So:
plot(I,U1);
that gives me a nice view.
plot(I,U1, I, U2);
That gives me the wrong window and I can't see the interesting parts. What is going on?
Amit
Amit 2014년 1월 16일
편집: Amit 2014년 1월 16일
The problem is that they intersect between 0 and 0.001 and 0 to 200 is a much bigger range for this. Try this
function polarisatiecurve
P = 100;
I = 0:0.000001:0.001;
U1 = P./I;
U2 = 800*(I+19).^2 - 2*(I+19).^3;
plot(I,U1,'b',I,U2,'r'); %,[0,100,0,600]);
%subplot (1,2,1);
xlabel('Stroom (A)')
ylabel('Spanning (V)')
title('Polarisatiecurve')
axis([0 0.001 0 0.5e6])
grid on
grid on
end
N/A
N/A 2014년 1월 16일
Never mind, I needed to add an axis options after the plotting function. Thank you so much for helping me!

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

추가 답변 (0개)

카테고리

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

질문:

N/A
2014년 1월 16일

댓글:

N/A
2014년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by