plotting functions with different sizes
이전 댓글 표시
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
Cris LaPierre
2021년 5월 3일
편집: Cris LaPierre
2021년 5월 3일
Your code has an error preventing it from running.
Line 6 has this error:
Unrecognized function or variable 'ppu'.
Osama Aliwat
2021년 5월 3일
Osama Aliwat
2021년 5월 3일
DGM
2021년 5월 3일
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
2021년 5월 3일
Osama Aliwat
2021년 5월 3일
KSSV
2021년 5월 3일
You need to rethink on your code. What exactly you are trying to achieve?
Osama Aliwat
2021년 5월 3일
DGM
2021년 5월 3일
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.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Geographic Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
