Why are my line plots are coming out improperly?

5 visualizaciones (últimos 30 días)
Pragyan Kumar Sarma
Pragyan Kumar Sarma el 18 de Abr. de 2023
Movida: VBBV el 23 de Abr. de 2023
The plot lines generated from the code below are coming out in improper way. I have attached an image file of the plot as well. The line generated from h4 and h8 are coming in an odd manner. Can I know why is it coming out in such a way?
clc;clear;close all;
%for head on collision
L= 4;
D= 3.860;
lam= 0.397;
% lamda will go from 0.4 m/sec (water, 0.25, 0.5, 0.75, 1) then 1m/sec
% (same thing) and finally 1.65 m/sec (same thing)
lam_org= [0.394 0.2091 0.284 0.404 0.374 0.423 0.358 0.523 0.493 0.567 0.359 0.424 0.296 0.445 0.447];
%lam_15_times = [0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397 0.397];
lam_l = log(lam_org);
psi_e= (2^0.33)/(2-lam);
Oh= 10^(-3)*[1.679 2.457 2.679 2.922 3.398 1.597 2.1782 2.505 2.958 1.487 3.129 1.934 2.478 2.728 2.893];
md_ho = [1.0690 2.02 1.3474 1.3580 1.3966 1.6701 1.4901 1.669 1.476 2.848 1.3871 2.8008 3.0724 2.3614 2.7726];
L_o = log(md_ho);
We = [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
We_log = log(We);
%for 2mm offset
md_2= [1.0431 1.1251 0.9519 0.9691 0.9380 1.5003 1.2390 1.3260 1.2584 2.2003 1.2260 1.9754 2.125 1.6842 2.098];
L_2 = log(md_2);
We= [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
%for 3mm offset
md_3= [0.9819 0.9916 1.0444 0.9938 0.9807 1.3555 1.2052 1.227 1.1849 1.747 1.2106 1.5462 1.6876 1.5860 1.726];
L_3 = log(md_3);
We= [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
%for 4mm offset
md_4= [1.015 0.9875 1.0682 1.0763 1.0021 1.295 1.119 1.1112 1.125 1.681 1.1667 1.6932 1.862 1.677 1.6443 ];
L_4 = log(md_4);
We= [8.518 9.903 16.473 22.68 26.214 58.84 78.77 117.76 138.37 184.842 193.155 272.054 327.49 443.05 615.34];
for i= 1:length(We)
psi_m(i)= 0.9759*((1+L/D)^(-0.7594))*We(i).^0.2283; % Graham et al.
end
for j=1:length(We)
psi2_m(j)= (D+L)*We(j).^0.25; % Clanet et al.
end
for k= 1:length(We)
for l= 1:length(Oh)
psi_m3(k,l)= 0.8353*(psi_e^0.3774)*(We(k)^0.0571)*(Oh(l)^(-0.0430)); % Li et al.
end
end
for m= 1: length(We)
for n= 1: length(lam_org)
psi_m_4(m,n)= 0.6046*(We(m)^0.1453)*(lam_org(n)^(-0.1062)); % my correlation
end
end
%h1= plot(We,md_ho,'s','MarkerFaceColor','red','MarkerEdgeColor','black','MarkerSize',9); hold on
%h5= plot(We,md_2,'o','MarkerFaceColor','red','MarkerEdgeColor','black','MarkerSize',9); hold on
%h6= plot(We,md_3,'<','MarkerFaceColor','green','MarkerEdgeColor','black','MarkerSize',9); hold on
h7= plot(We,md_4,'d','MarkerFaceColor','red','MarkerEdgeColor','black','MarkerSize',9); hold on
pcoeff= polyfit(We,md_4,2)
%pcoeff2= polyfit(We,md_ho,2)
%axis([0 625 0 0.5]);
yp= polyval(pcoeff,We);
%yp2= polyval(pcoeff2,We);
h2= plot(We,yp,'k','LineWidth',1.2); hold on
h3= plot(We,psi_m, 'b','LineWidth', 1.5); hold on % (psi_m is the Graham-Farhangi's correlated maximum deformation)
%plot(We,psi2_m,'LineStyle','--','Color','g','LineWidth',1.5); %(Clanet et al's correlation)
h4= plot(We,psi_m3,'LineStyle','-.','Color','#0B0'); hold on %(Li et al's correlation)
h8= plot(We,psi_m_4,'LineStyle','-','LineWidth',1.2,'Color','magenta');
%p = polyfit(We,md_ho, 1);
%px = [min(We) max(We)];
%py = polyval(p, px);
%hold on
%plot(px, py, 'LineWidth', 2);
legend([h7(1), h2(1), h3(1),h4(1), h8(1)], 'Experimental data for \lambda = 0.397 (4mm offset)','Fitted curve', 'Graham et al.','Li et al.', 'my correlation');
xlabel('We','FontSize',14,'FontWeight','normal');ylabel('\psi_{max}','FontSize',16,'FontWeight','bold');
  9 comentarios
dpb
dpb el 19 de Abr. de 2023
Vector multiplication of what??? An Nx1 by 1xN results in an NxN while a [1xN] by [Nx1] yields a single value. Neither of those two possibilities will result in a 1xN vector that you say you want/were expecting.
It certainly is not at all clear just what any of this means or how to try to interpret the two variables in each of the "correlations". You've got 15 values of two variables each, but what either of those represents and how they were determined is completely a black box to us.
It certainly isn't at all clear where the formulations you're using come from or what they are trying to correlate; it certainly is especially unclear in your correlation where there are the two variables(?) as to what it means that both are changing and how that relates to anything else...but the only way to get the 1x15 vector is as we've shown, use the two pairwise for each element in the two vectors. Now, whether that makes any sense or not to have done so is another question entirely. We have absolutely no way to know about that from what information has been shared here.
Torsten
Torsten el 19 de Abr. de 2023
Editada: Torsten el 19 de Abr. de 2023
If you want
a = [1 2 3];
b = [4 25 36];
c = a.^2.*b.^0.5
c = 1×3
2 20 54
then you found what you are looking for.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 18 de Abr. de 2023
Movida: dpb el 18 de Abr. de 2023
Well, there's no "problem" with the nested loop other than apparently it isn't what you intended... :) It iterates through each value of the Oh or lam_org for each We in turn.
If the intent is instead to use the i_th value of each We and Oh at the same time such that both are changing simultaneously but the combinations of I,J for I~=J aren't computed, then you don't need (or want) the nested loop but just a single loop -- or, in MATLAB don't need the loop at all;, just write the vectorized expressions.
...
for k= 1:length(We)
psi_m3(k)= 0.8353*(psi_e^0.3774)*(We(k)^0.0571)*(Oh(k)^(-0.0430)); % Li et al.
psi_m_4(k)= 0.6046*(We(k)^0.1453)*(lam_org(k)^(-0.1062)); % my correlation
end
where I've moved them both into a single loop since iterating over same thing for both.
"The MATLAB way" to do the above is to use the "dot" operators and vectorize the expressions...
psi_m3 = 0.8353*(psi_e^0.3774).*(We.^0.0571).*(Oh.^(-0.0430)); % Li et al.
psi_m_4= 0.6046*(We.^0.1453).*lam_org.^(-0.1062); % my correlation
See the doc for times, .* to learn about element-wise operators.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by