plotting functions with different sizes
Afficher commentaires plus anciens
s=1; xs=1.5836; vp=1; k=0.63; em=2.5; ppu=0.8; ps=0.95; sm=10;
q=-s:0.001:s;
stepE=vp:0.001:0.9*em;
radRNG=(stepE*vp)/xs;
r=radRNG-k;
y=(r-ppu*(sm/100));
if y<0
y=-y;
end
x=-(sqrt((r).^2-((y).^2)));
n=length(q);
for i=1:n
if q(i)>=-k & q(i)<=(0.9*em*vp)./xs
p(i)=sqrt(r.^2-x.^2);
elseif q(i)>=(0.9*em*vp)./xs & q(i)<=ps
p(i)=sqrt(s.^2-q(i).^2);
elseif q(i)>ps & q(i)<=s
p(i)=0;
end
end
p(p>ppu)=ppu;
figure(1)
plot(q,p)
ylim([0 s])
xlim([-s s])
xlabel('Q in p.u'); ylabel('P in p.u')
How can I plot these functions assuming i have different sizes ? I have x and y as points in first if statement with different size than q and i want to plot
9 commentaires
Cris LaPierre
le 3 Mai 2021
Modifié(e) : Cris LaPierre
le 3 Mai 2021
Your code has an error preventing it from running.
Line 6 has this error:
Unrecognized function or variable 'ppu'.
Osama Aliwat
le 3 Mai 2021
Osama Aliwat
le 3 Mai 2021
DGM
le 3 Mai 2021
1: sm is undefined
2: This is assigning a vector to a single element of another vector
p(i)=sqrt(r.^2-x.^2);
3: You say "how can i plot these functions" -- Other than p, which functions?
Osama Aliwat
le 3 Mai 2021
Osama Aliwat
le 3 Mai 2021
KSSV
le 3 Mai 2021
You need to rethink on your code. What exactly you are trying to achieve?
Osama Aliwat
le 3 Mai 2021
DGM
le 3 Mai 2021
It almost looks like you're trying to plot a piecewise 1D function of q, but your intervals all overlap, so I have no idea what you're actually trying to plot.
% your plotting intervals in terms of q:
% interval 1 is [-k (0.9*em*vp)/xs]
% interval 2 is (-inf ps] & [(0.9*em*vp)/xs inf)
% interval 3 is (ps s]
% so the intervals stack up like
% [-0.63 -------------- 1.42]
% (-inf --------- 0.95] [1.42 -------------- inf)
% [0.95 -- 1.00]
% but q is only defined over [-1 1]
Furthermore, the function that would be plotted in interval 1 isn't even a function of q, so the idea that this is a piecewise function of q doesn't make much sense to me. In fact, this whole thing:
if y<0
y=-y;
end
x=-(sqrt((r).^2-((y).^2)));
% ...
p=sqrt(r.^2-x.^2);
Is a convoluted way of saying:
p = abs(y);
I don't even see that x or y are used for anything else.
You're going to have to figure out what you're trying to plot and how you want it plotted. I can't tell.
Réponses (0)
Catégories
En savoir plus sur Geographic Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
