I would like to know how to get the data plotted by the script I have made. It was the solution of a pdepe problem. Thank you

4 comentarios

Olawale Ikuyajolu
Olawale Ikuyajolu el 2 de Mayo de 2020
save function?
Adrian Oblena
Adrian Oblena el 2 de Mayo de 2020
I have this code and I want to get the data used to plot once you run my script. Below is my script.
function AdvDiff
m=0;
x=linspace(0,1,10);
t=linspace(0,1,10);
sol = pdepe(m,@AdvDiffpde,@AdvDiffic,@AdvDiffbc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot
surf(x,t,u)
title('Advection Diffusion')
xlabel('Distance,x')
ylabel('Time,t')
zlabel('Concentration,C')
% A solution profile
figure
plot(x,u(end,:))
title('Advection Diffusion')
xlabel('Distance,x')
ylabel('Concentration,C')
grid on
axis tight
end
%PDE for Advection Diffusion Equation
function [c,f,s] = AdvDiffpde(x,t,u,DuDx)
c = 1;
f = DuDx;
s = -u*DuDx;
end
%Initial Condition Function
function u0 = AdvDiffic(x)
u0 = exp(-x);
end
%Boundary Condition Functions
function [pl,ql,pr,qr] = AdvDiffbc(xl,ul,xr,ur,t)
pl = ul+t-1;
ql = 0;
pr = ur-(1-t)/exp(1);
qr = 0;
end
Olawale Ikuyajolu
Olawale Ikuyajolu el 2 de Mayo de 2020
Do you want to get x and u?
Adrian Oblena
Adrian Oblena el 2 de Mayo de 2020
I want to get u(x,t)
for every x and t

Iniciar sesión para comentar.

 Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 2 de Mayo de 2020
Editada: KALYAN ACHARJYA el 2 de Mayo de 2020

0 votos

Assign those varibles as output arguments
function [u,data2,x_data]=AdvDiff
m=0;
x=linspace(0,1,10);
t=linspace(0,1,10);
sol = pdepe(m,@AdvDiffpde,@AdvDiffic,@AdvDiffbc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot
surf(x,t,u)
title('Advection Diffusion')
xlabel('Distance,x')
ylabel('Time,t')
zlabel('Concentration,C')
% A solution profile
figure
data2=u(end,:);
plot(x,data2);
title('Advection Diffusion')
xlabel('Distance,x')
ylabel('Concentration,C')
grid on
axis tight
end
Call the dunctions with output arguments (Make all variable as output arguments, those data you needed in the currect working directory)
Example:
>> [u,data2,x_data]=AdvDiff
u =
1.0000 0.8948 0.8007 0.7165 0.6412 0.5738 0.5134 0.4594 0.4111 0.3679
0.8889 0.8584 0.8154 0.7624 0.7018 0.6356 0.5652 0.4908 0.4119 0.3270
0.7778 0.7671 0.7441 0.7092 0.6632 0.6067 0.5401 0.4642 0.3793 0.2861
0.6667 0.6657 0.6528 0.6279 0.5911 0.5427 0.4832 0.4131 0.3334 0.2453
0.5556 0.5612 0.5552 0.5376 0.5083 0.4677 0.4161 0.3544 0.2834 0.2044
0.4444 0.4560 0.4562 0.4451 0.4229 0.3899 0.3466 0.2938 0.2323 0.1635
0.3333 0.3509 0.3573 0.3527 0.3375 0.3121 0.2771 0.2331 0.1812 0.1226
0.2222 0.2461 0.2589 0.2610 0.2529 0.2351 0.2082 0.1730 0.1305 0.0818
0.1111 0.1418 0.1614 0.1704 0.1695 0.1592 0.1404 0.1138 0.0803 0.0409
-0.0000 0.0381 0.0648 0.0810 0.0874 0.0847 0.0738 0.0554 0.0305 0
data2 =
-0.0000 0.0381 0.0648 0.0810 0.0874 0.0847 0.0738 0.0554 0.0305 0
x_data =
0 0.1111 0.2222 0.3333 0.4444 0.5556 0.6667 0.7778 0.8889 1.0000
Now output aruguments are avalible in workspace, thease variable are avalible outside if the function also
See the function file, if you execute the main code without function file, all varible are avalible in workspace. Suggested tho see the documentation (Matlab Function Declaration) and another way define those variables as global variables, please go through this.
Any issue let me know

1 comentario

Adrian Oblena
Adrian Oblena el 2 de Mayo de 2020
This is really a great help. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 2 de Mayo de 2020

Editada:

el 2 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by