how to plot two m.file in one plot

i have two PDE each one i calculated in m.file, but i want to draw the output of first one as x, and the second as y
how can i do that

 採用された回答

Dyuman Joshi
Dyuman Joshi 2024 年 2 月 18 日

0 投票

Call both the PDEs in a new script/function and plot accordingly.

7 件のコメント

br
br 2024 年 2 月 18 日
i write it like this but it's not work, and also it's not seems to be right
kp0=140270;
Eap=43900;
kd0=0.355;
Ead=17400;
T=333;
kp=kp0*exp(-Eap/(8.314*T));
kd=kd0*exp(-Ead/(8.314*T));
m=2;
t=linspace(0,3600,1000);
u=linspace(0.036405,111.3494528,1000);
x=linspace(0,0.036405,1000);
x1=pdepe(m,@(x,t,u,DuDx)eqn111(x,t,u,DuDx,T),@initial111,@(xl,ul,xr,ur,t)bc111(xl,ul,xr,ur,t,kp,kd),u,t);
u1=pdepe(m,@(x,t,u,DuDx)eqn11(x,t,u,DuDx,T),@initial11,@(xl,ul,xr,ur,t)bc11(xl,ul,xr,ur,t,kp,kd),x,t);
t_indices = find(t >= 0 & t <= 3600);
figure
hold on
for j = t_indices
plot(x1(j,:),u(j,:));
hold off
end
xlabel('radius');
ylabel('concentration');
Dyuman Joshi
Dyuman Joshi 2024 年 2 月 18 日
"i write it like this but it's not work, and also it's not seems to be right"
Please specify how it is not working.
Why does it not seem right?
br
br 2024 年 2 月 18 日
it's give me an error
Dyuman Joshi
Dyuman Joshi 2024 年 2 月 18 日
Please share -
1 - the full error message i.e. all of the red text.
2 - the PDE files (eqn111, initial111 and eqn11, initial11). Use the paperclip button to attach.
br
br 2024 年 2 月 18 日
Error using pdepe
The entries of XMESH must be strictly increasing.
Error in runnnn (line 11)
for u=pdepe(m,@(x,t,u,DuDx)eqn11(x,t,u,DuDx,T),@initial11,@(xl,ul,xr,ur,t)bc11(xl,ul,xr,ur,t,kp,kd),x,t);
function [c,f,s]=eqn111(x,t,u,DuDx,T)
c=1;
f=(1.34*10^-7)*exp(-16000/(8.314.*T))*exp(-(0.57*1.225+0.43*1.005*0.524)/(0.57*2.91*(-8.675+T)+0.43*0.5*(-205+T)))*DuDx;
s=0;
end
----------------------------------------------------------------------------------------
function value=initial11(x)
value=0;
-----------------------------------------------------------------------------
function [c,f,s]=eqn11(x,t,u,DuDx,T)
c=1;
f=(1.34*10^-6)*exp(-16000/(8.314.*T))*exp(-(0.57*1.225+0.43*1.005*0.524)/(0.57*2.91*(-8.675+T)+0.43*0.5*(-205+T)))*DuDx;
s=0;
end
------------------------------------------------------------------------------
function value=initial11(u)
value=0.036405;
Torsten
Torsten 2024 年 2 月 18 日
Please include the complete code with error message that demonstrates the problem you have.
The functions you provided don't suffice and some are duplicates.
kp0=140270;
Eap=43900;
kd0=0.355;
Ead=17400;
T=333;
kp=kp0*exp(-Eap/(8.314*T));
kd=kd0*exp(-Ead/(8.314*T));
m=2;
t=linspace(0,3600,1000);
u=linspace(0.036405,111.3494528,1000);
x=linspace(0,0.036405,1000);
x1=pdepe(m,@(x,t,u,DuDx)eqn111(x,t,u,DuDx,T),@initial111,@(xl,ul,xr,ur,t)bc111(xl,ul,xr,ur,t,kp,kd),u,t);
u1=pdepe(m,@(x,t,u,DuDx)eqn11(x,t,u,DuDx,T),@initial11,@(xl,ul,xr,ur,t)bc11(xl,ul,xr,ur,t,kp,kd),x,t);
t_indices = find(t >= 0 & t <= 3600);
figure
hold on
for j = t_indices
plot(x1(j,:),u(j,:));
hold off
end
xlabel('radius');
ylabel('concentration');
function [c,f,s]=eqn111(x,t,u,DuDx,T)
c=1;
f=(1.34*10^-7)*exp(-16000/(8.314.*T))*exp(-(0.57*1.225+0.43*1.005*0.524)/(0.57*2.91*(-8.675+T)+0.43*0.5*(-205+T)))*DuDx;
s=0;
end
%----------------------------------------------------------------------------------------
function value=initial11(x)
value=0;
end
%-----------------------------------------------------------------------------
function [c,f,s]=eqn11(x,t,u,DuDx,T)
c=1;
f=(1.34*10^-6)*exp(-16000/(8.314.*T))*exp(-(0.57*1.225+0.43*1.005*0.524)/(0.57*2.91*(-8.675+T)+0.43*0.5*(-205+T)))*DuDx;
s=0;
end
%------------------------------------------------------------------------------
function value=initial11(u)
Function 'initial11' has already been declared within this scope.
value=0.036405;
end
br
br 2024 年 2 月 19 日
thanks a lot

サインインしてコメントする。

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 2 月 18 日

0 投票

use plot(x, y), e.g.:
x = [-5:5;2*(-5:5); 3*(-5:5)];
y = [3*x.^2+3*x-3; -5*x.^2+5*x-15; -2*x.^2-3*x-13;];
plot(x(1,:),y(1,:), 'ro-', x(2,:),y(2,:), 'kp:', x(3,:),y(3,:), 'b--', 'LineWidth', 2)
grid on
xlabel ('x')
ylabel ("y(x)")
legend('Set 1', 'Set 2', 'Set 3', 'Location', 'Best')

1 件のコメント

br
br 2024 年 2 月 18 日
thanks a lot, but each parameter x and u are in differant m.file how to combine them?

サインインしてコメントする。

製品

リリース

R2023b

質問済み:

br
2024 年 2 月 18 日

コメント済み:

br
2024 年 2 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by