plot a graph from loop

3 Ansichten (letzte 30 Tage)
Alina Abdikadyr
Alina Abdikadyr am 17 Feb. 2023
Kommentiert: Star Strider am 17 Feb. 2023
Hello everyone!
Please, could you help me to plot the graphs using the loop
So, in my code I have the range of nv (nv=nmin:0.1:nmax)
for each value of nv, it plots the different parabolas. In figure 1, R vs V graph is plotted.
How to plot the graph of R vs V? (R depends on V by formula used in loop). I tried to implement nnew, but it gives me constan values.
So V is caluclated in loop. At the end, I have to get a graph of nv vs V (where V is changing parabolically with n).
At the end if i look at my genereted 10X45 matrix of c (which is the value of V) and 10X45 matrix of Rv (which is the value of Rv).
for each iteration i need to plot graphs in one figure. take the values of 2nd row of V and 2nd row of Rv
My code is:
clear all; close all
W = 10000;
S = 40;
AR=7;
cd0 = 0.005;
k = 1/pi/AR;
Psl=25000;
clalpha = 2*pi;
cdmin=4*cd0;
clmin=sqrt(3*cd0/k);
figure(1);hold on; xlabel('V');ylabel('P');
fun=@(n1) n1*W*(cdmin/clmin)*sqrt(2*n1*W/(1.225*S*clmin))-25000;
nmax = fzero(fun,2);
nmin=1/cos(0);
nv=nmin:0.1:nmax;
g=9.81;
%3.1
for k1 = 1:numel(nv)
n = nv(k1);
i=0;
for alpha = 1:0.25:12
i=i+1;
cl(i) = clalpha * alpha * pi/180;
V(i) = sqrt(2*n*W/1.225/S/cl(i));
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = n*W*cd(i)/cl(i);
P(i) = D(i)*V(i);
P_a(i)=Psl;
R(i)=V(i)*V(i)/(g*sqrt(n*n-1));
T(i)=2*pi*R(i)/V(i);
end
c(k1,:) = V;
Pm(k1,:) = P;
Pma(k1,:) = P_a;
Rv(k1,:)=R;
xix = find(diff(sign(D.*V-P_a)));
if ~isempty(xix)
for k3 = 1:numel(xix)
idxrng = max(xix(k3)-1,1) : min(numel(V),xix(k3)+1);
xv(k3) = interp1(P(idxrng)-P_a(idxrng), V(idxrng), 0);
yv(k3) = interp1(V(idxrng),P(idxrng), xv(k3));
Xm{k1,k3} = xv(k3); % Intersection X-Matrix
Ym{k1,k3} = yv(k3); % Intersection Y-Matrix
end
end
figure(1); plot(V,P)
hold on
plot(V,P_a)
plot(xv, yv, 's', 'DisplayName',sprintf('Intersections %d',k1)) % Plot Intersections (Optional)
[minV,Vnidx] = min(V);
Vstall(k1,:) = minV;
Pstall(k1,:) = P(Vnidx);
nvv(:,k1)=nv;
[Pmin,idx] = min(P);
minP(k1,:) = Pmin;
Vm(k1,:) = V(idx);
N=nvv(:,1);
Vminp=Vm(:,1);
figure(2); plot(c,Rv)
figure(3); plot(V,T)
end
Table = cell2table(cat(2,Xm,Ym), 'VariableNames',{'V_p_max','V_p_min','Pmax','Pmin'});
Table = addvars(Table, Vstall, 'After','V_p_min');
Table = addvars(Table, N, 'Before','V_p_max');
Table = addvars(Table, Pstall, minP,Vminp, 'After','Pmin');
  2 Kommentare
Mathieu NOE
Mathieu NOE am 17 Feb. 2023
hello
P is an array size 1 x 45
how do you wnt to plot P vs n which is a scalar
same reamark with nv wich size is 1 x 10
maybe you wanted one specific P value for each iteration ? like Pmin vs nv ?
Alina Abdikadyr
Alina Abdikadyr am 17 Feb. 2023
sorry, i modified my question

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 17 Feb. 2023
One of the possible ways to plot nv vs, V is to include cl values that leads to 3D plot, e.g.:
...
alpha = 1:0.25:12;
nv=nmin:0.1:nmax;
[ALF, NV]=meshgrid(alpha, nv);
CL = clalpha * ALF * pi/180;
Vall = sqrt(2*NV*W/1.225/S./CL);
surfc(ALF, CL, Vall)

Star Strider
Star Strider am 17 Feb. 2023
Plotting ‘R’ as a function of ‘V’ is relatively straightforward:
figure
plot(V, R)
grid
xlabel('V')
ylabel('R')
What do you want to do with it afterwards?
clear all; close all
W = 10000;
S = 40;
AR=7;
cd0 = 0.005;
k = 1/pi/AR;
Psl=25000;
clalpha = 2*pi;
cdmin=4*cd0;
clmin=sqrt(3*cd0/k);
figure(1);hold on; xlabel('V');ylabel('P');
fun=@(n1) n1*W*(cdmin/clmin)*sqrt(2*n1*W/(1.225*S*clmin))-25000;
nmax = fzero(fun,2);
nmin=1/cos(0);
nv=nmin:0.1:nmax;
g=9.81;
%3.1
for k1 = 1:numel(nv)
n = nv(k1);
i=0;
for alpha = 1:0.25:12
i=i+1;
cl(i) = clalpha * alpha * pi/180;
V(i) = sqrt(2*n*W/1.225/S/cl(i));
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = n*W*cd(i)/cl(i);
P(i) = D(i)*V(i);
P_a(i)=Psl;
R(i)=V(i)*V(i)/(g*sqrt(n*n-1));
T(i)=2*pi*R(i)/V(i);
end
c(k1,:) = V;
Pm(k1,:) = P;
Pma(k1,:) = P_a;
Rv(k1,:)=R;
xix = find(diff(sign(D.*V-P_a)));
if ~isempty(xix)
for k3 = 1:numel(xix)
idxrng = max(xix(k3)-1,1) : min(numel(V),xix(k3)+1);
xv(k3) = interp1(P(idxrng)-P_a(idxrng), V(idxrng), 0);
yv(k3) = interp1(V(idxrng),P(idxrng), xv(k3));
Xm{k1,k3} = xv(k3); % Intersection X-Matrix
Ym{k1,k3} = yv(k3); % Intersection Y-Matrix
end
end
figure(1); plot(V,P)
hold on
plot(V,P_a)
plot(xv, yv, 's', 'DisplayName',sprintf('Intersections %d',k1)) % Plot Intersections (Optional)
[minV,Vnidx] = min(V);
Vstall(k1,:) = minV;
Pstall(k1,:) = P(Vnidx);
nvv(:,k1)=nv;
[Pmin,idx] = min(P);
minP(k1,:) = Pmin;
Vm(k1,:) = V(idx);
N=nvv(:,1);
Vminp=Vm(:,1);
figure(2); plot(c,Rv)
figure(3); plot(V,T)
end
figure
plot(V, R)
grid
xlabel('V')
ylabel('R')
figure
plot(V, R, 'LineWidth',2, 'DisplayName','R(V)')
hold on
plot(c,Rv, 'DisplayName','Rv(c)')
hold off
grid
xlabel('V')
ylabel('R')
% legend('Location','eastoutside')
Table = cell2table(cat(2,Xm,Ym), 'VariableNames',{'V_p_max','V_p_min','Pmax','Pmin'});
Table = addvars(Table, Vstall, 'After','V_p_min');
Table = addvars(Table, N, 'Before','V_p_max');
Table = addvars(Table, Pstall, minP,Vminp, 'After','Pmin');
.
  2 Kommentare
Alina Abdikadyr
Alina Abdikadyr am 17 Feb. 2023
Thank you!
Could you please me to plot in one graph. I have a formula of R=V^2/(9.81*sqrt(n^2-1)) for a constant V I should plot R and n curve, and for constant n I should plot V n curve
Star Strider
Star Strider am 17 Feb. 2023
My pleasure!
I do not understand what you want to do. You plotted those together, however the ‘R’ here does not appear to be the same ‘R’ I plotted (and the only ‘R’ that I can find in your code).
What vectors are you plotting here, and where in your code are they calculated?
What constant values for ‘V’ and ‘n’ do you want to use?
Also, the ‘R’ and ‘n’ curves are not going to intersect when plotted on the same axes scales. What do you want to do with them?
My apologies, however I am confused here.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by