Hello :) I have encountered a problem with my code in matlab
I would like to plot a graph with all these condtions but i don't know how to make it
All the calculs here are correct by the way but i don't know how the for loop with the if condition work with the plot function
can someone help me ?
for s=0:0.1:1;
if s > 0 & s <1 %avoid dividing by 0
Z2=sqrt((X.^2)+(R2./s).^2);
I1=U./(sqrt(X.^2+(R2./s).^2));
Pa=(U.^2./Rf)+(I1.^2).*(R2./s);
Q=(U.^2./Xm)+(I1.^2).*X;
Pr=(I1.^2)*R2./s;
Pjr=I1.^2*R2;
Pmc=Pr-Pjr;
rendement=Pmc/Pa;
N=Ns.*(1-s);
else
N =0;
rendement=0;
end
figure(6)
plot(N,rendement)

 Akzeptierte Antwort

Alan Stevens
Alan Stevens am 29 Apr. 2021

0 Stimmen

Do you mean like this:
s = 0:0.1:1;
for i=1:numel(s)
if s(i) > 0 && s(i) <1 %avoid dividing by 0
Z2=sqrt((X.^2)+(R2./s(i)).^2);
I1=U./(sqrt(X.^2+(R2./s(i)).^2));
Pa=(U.^2./Rf)+(I1.^2).*(R2./s(i));
Q=(U.^2./Xm)+(I1.^2).*X;
Pr=(I1.^2)*R2./s(i);
Pjr=I1.^2*R2;
Pmc=Pr-Pjr;
rendement(i)=Pmc/Pa;
N(i)=Ns.*(1-s(i));
else
N(i) =0;
rendement(i)=0;
end
end
figure(6)
plot(N,rendement)

1 Kommentar

Julien Daltin
Julien Daltin am 29 Apr. 2021
Bearbeitet: Julien Daltin am 29 Apr. 2021
Yes something like that ! But i saw that ia have a mistake , because when s = 1 → N=1500 and rendement = 0 too , but i will try by myself ! Thank you !!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 29 Apr. 2021
Bearbeitet: Jan am 29 Apr. 2021

1 Stimme

figure;
axes('NextPlot', 'add'); % as: hold on
for s = 0:0.1:1
if s > 0 & s < 1 %avoid dividing by 0
Z2 = sqrt((X.^2) + (R2 ./ s).^2);
I1 = U ./ (sqrt(X.^2 + (R2 ./ s).^2));
Pa = (U .^2 ./ Rf) + (I1.^2) .* (R2 ./ s);
Q = (U .^2 ./ Xm) + (I1.^2) .* X;
Pr = (I1.^2) * R2 ./ s;
Pjr = I1.^2 * R2;
Pmc = Pr - Pjr;
rendement=Pmc / Pa;
N = Ns .* (1 - s);
plot(N, rendement, 'b.')
end
end

Kategorien

Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by