Plot a 2d figure for a complicated function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi. I wanted to plot a 2d figure for the equation below (lambda) that are a function of c, but it doesn't give me any figures. Could you please tell me what is my problem? Thanks in advance for any help
vplc=0.25;delta=2.5;tau_max=44000;Ktau=0.045;%tauP=0.027;
kc=0.1; kh=0.05;Vp=0.9;Kbar=0.000015;kp=0.15;gamma=5.5;kb=0.4;
Vpm=0.000159;Kpm=0.15;alpha0=.00000681;alpha1=0.0000227;Ke=7;vs=0.002;ks=0.1;
Kf=0.18;kplc=0.055;ki=2;gamma=5.5;kipr=0.18;
[c]=meshgrid(0.001:0.005:1);
%[c]=meshgrid(0.002:0.005:1);
%c=0.07362169;h=0.5823305;ce=16.64219;p=0;
p=(vplc./ki).*(c.^2./((kplc).^2+c.^2));
h=kh.^4./(c.^4+kh.^4);
Po=(p.^2.*c.^4.*h)./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4));
A=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^4.*c.^8.*h.*(1+kb))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
B=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^2.*c.^4.*h.*(4.*c.^3.*p.^2.*h.*(1+kb)+4.*c.^3.*kb.*kp.^2))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
T=kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)-c.^4.*(1./tau_max);
D=(kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)).*(-c.^4.*(1./tau_max))-((kipr.*B.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))).*(c.^4.*(1./tau_max).*((-4.*c.^3.*kh.^4)./(c.^4+kh.^4).^2)));
lambda=(T+sqrt(T.^2-4.*D))./2;
plot(c,lambda)
hold on
0 件のコメント
採用された回答
Voss
2022 年 7 月 20 日
vplc=0.25;delta=2.5;tau_max=44000;Ktau=0.045;%tauP=0.027;
kc=0.1; kh=0.05;Vp=0.9;Kbar=0.000015;kp=0.15;gamma=5.5;kb=0.4;
Vpm=0.000159;Kpm=0.15;alpha0=.00000681;alpha1=0.0000227;Ke=7;vs=0.002;ks=0.1;
Kf=0.18;kplc=0.055;ki=2;gamma=5.5;kipr=0.18;
c is a matrix where every row is identical
[c]=meshgrid(0.001:0.005:1)
% is c equivalent to repeated copies of its first row?
isequal(c,repmat(c(1,:),size(c,1),1))
% c = 0.001:0.005:1;
%[c]=meshgrid(0.002:0.005:1);
%c=0.07362169;h=0.5823305;ce=16.64219;p=0;
p=(vplc./ki).*(c.^2./((kplc).^2+c.^2));
h=kh.^4./(c.^4+kh.^4);
Po=(p.^2.*c.^4.*h)./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4));
A=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^4.*c.^8.*h.*(1+kb))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
B=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^2.*c.^4.*h.*(4.*c.^3.*p.^2.*h.*(1+kb)+4.*c.^3.*kb.*kp.^2))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
T=kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)-c.^4.*(1./tau_max);
D=(kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)).*(-c.^4.*(1./tau_max))-((kipr.*B.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))).*(c.^4.*(1./tau_max).*((-4.*c.^3.*kh.^4)./(c.^4+kh.^4).^2)));
lambda=(T+sqrt(T.^2-4.*D))./2;
so lambda is also a matrix with every row identical
% is lambda equivalent to repeated copies of its first row?
isequal(lambda,repmat(lambda(1,:),size(lambda,1),1))
Using plot with matrices, one line is created for each column of the matrices
h = plot(c,lambda) % 200 lines plotted
So when every row is the same, you get lines consisting of multiple copies (200 in this case) of the same point.
get(h(1),'XData') % x-coordinates of the points in the first line
get(h(1),'YData') % y-coordinates of the points in the first line
You can use a data marker to see the points/lines:
h = plot(c,lambda,'.') % different colored points for different lines
Therefore, since c is redundant, in that it is a matrix consisting of 200 copies of the same row, perhaps it should be a vector?
c = 0.001:0.005:1;
%c=0.07362169;h=0.5823305;ce=16.64219;p=0;
p=(vplc./ki).*(c.^2./((kplc).^2+c.^2));
h=kh.^4./(c.^4+kh.^4);
Po=(p.^2.*c.^4.*h)./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4));
A=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^4.*c.^8.*h.*(1+kb))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
B=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^2.*c.^4.*h.*(4.*c.^3.*p.^2.*h.*(1+kb)+4.*c.^3.*kb.*kp.^2))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
T=kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)-c.^4.*(1./tau_max);
D=(kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)).*(-c.^4.*(1./tau_max))-((kipr.*B.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))).*(c.^4.*(1./tau_max).*((-4.*c.^3.*kh.^4)./(c.^4+kh.^4).^2)));
lambda=(T+sqrt(T.^2-4.*D))./2;
In which case lambda, T and D are also vectors of the same size, so plotting them is no problem:
figure % using different widths and styles to distinguish the lines:
plot(c,lambda,'LineWidth',3) % thick blue line
hold on
plot(c,T) % red line
hold on
plot(c,D,'--','LineWidth',2) % dashed yellow line
その他の回答 (1 件)
Chunru
2022 年 7 月 20 日
vplc=0.25;delta=2.5;tau_max=44000;Ktau=0.045;%tauP=0.027;
kc=0.1; kh=0.05;Vp=0.9;Kbar=0.000015;kp=0.15;gamma=5.5;kb=0.4;
Vpm=0.000159;Kpm=0.15;alpha0=.00000681;alpha1=0.0000227;Ke=7;vs=0.002;ks=0.1;
Kf=0.18;kplc=0.055;ki=2;gamma=5.5;kipr=0.18;
% grid
x = 0.001:0.005:1;
y = 0.001:0.005:1;
[c]=meshgrid(x, y);
%[c]=meshgrid(0.002:0.005:1);
%c=0.07362169;h=0.5823305;ce=16.64219;p=0;
p=(vplc./ki).*(c.^2./((kplc).^2+c.^2));
h=kh.^4./(c.^4+kh.^4);
Po=(p.^2.*c.^4.*h)./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4));
A=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^4.*c.^8.*h.*(1+kb))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
B=(4.*c.^3.*p.^2.*h.*(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^4+c.^4))-p.^2.*c.^4.*h.*(4.*c.^3.*p.^2.*h.*(1+kb)+4.*c.^3.*kb.*kp.^2))./(p.^2.*(1+kb).*c.^4.*h+kb.*kp.^2.*(kc.^2+c.^4)).^2;
T=kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)-c.^4.*(1./tau_max);
D=(kipr.*A.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))-kipr.*Po.*(1+gamma)-((2.*c.*vs.*(c.^2+ks.^2)-2.*vs.*c.^3)./(c.^2+ks.^2).^2)).*(-c.^4.*(1./tau_max))-((kipr.*B.*((vs.*c.^2./(c.^2+ks.^2)).*(1./kipr.*Po))).*(c.^4.*(1./tau_max).*((-4.*c.^3.*kh.^4)./(c.^4+kh.^4).^2)));
lambda=(T+sqrt(T.^2-4.*D))./2;
%whos
% This is a 3d plot rather than 2d plot
%plot(c,lambda)
surf(x, y, lambda, 'EdgeColor', 'none')
hold on
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!