- #1
Phys pilot
- 30
- 0
Hello,
I want to plot this PDE which is non homogeneous:
ut=kuxx+cut=kuxx+c
u(x,0)=c0(1−cosπx)u(x,0)=c0(1−cosπx)
u(0,t)=0u(1,t)=2c0u(0,t)=0u(1,t)=2c0
I have a code that can solve this problem and plot it with those boundary and initial conditions but not with the non homogeneous term.
But I don't know how to add that term, any ideas? I don't really understand the code very well. I just want to plot it. would it be very difficult?
The only idea I have is to divide the problem in two equations which sum would be the solution of the problem:
u(x,t)=v(x,t)+U(x)u(x,t)=v(x,t)+U(x)
kU(x)′′+c=0kU(x)″+c=0
U(x)=−cx22k+(2c0+c2k)xU(x)=−cx22k+(2c0+c2k)xand this other one
vt=kvxxvt=kvxx
Which I can solve and plot with my code. So, is there any way to plot the U and sum it to the plot of the second one over the time? thanks
I want to plot this PDE which is non homogeneous:
ut=kuxx+cut=kuxx+c
u(x,0)=c0(1−cosπx)u(x,0)=c0(1−cosπx)
u(0,t)=0u(1,t)=2c0u(0,t)=0u(1,t)=2c0
I have a code that can solve this problem and plot it with those boundary and initial conditions but not with the non homogeneous term.
Matlab:
function [u,er]=ftcs(t0,tf,nt,a,b,nx,ci,cca,ccb,dif,cada,sol)
% explicit method
%u solution
%er vector error
%t0 y tf time limits
%nt
%nx
%a b x value
%ci initial condition
%cca y ccb boundary conditions
%dif diffusion coefficient
%cada time lapse
%sol solution if it's known
x=linspace(a,b,nx); x=x'; dx=x(2)-x(1); %h
t=linspace(t0,tf,nt); t=t'; dt=t(2)-t(1); %k
r=dt/dx^2*dif;
if r>.5
clc
disp('stability not satisfied')
pause
end
di=1-2*r;
cca=inline(cca,'t');
ccb=inline(ccb,'t');
A=diag(di*ones(nx-2,1))+diag(r*ones(nx-3,1),1)+diag(r*ones(nx-3,1),-1);
A=[[r;zeros(nx-3,1)] A [zeros(nx-3,1);r]];
ci=vectorize(inline(ci,'x'));
u=ci(x); % vectorwith a solution for t=0, initial condition
gra=plot(x,u);
axis([a b min(u) max(u)])
pause
z=u;
u(1)=cca(t(1));
u(end)=ccb(t(1));
for i=1:nt-1;
u=A*u;
u=[cca(t(i+1)); u ; ccb(t(i+1))];
if mod(i,cada)==0
set(gra,'ydata',u');
pause(.1)
z(:,end+1)=u;
end
end
if nargin==12 & nargout==2
sol=vectorize(inline(sol,'x','t'));
er=u-sol(x,tf);
end
pause
figure
surfc(z);shading interp; colormap(hot);set(gca,'ydir','reverse');
rotate3d
But I don't know how to add that term, any ideas? I don't really understand the code very well. I just want to plot it. would it be very difficult?
The only idea I have is to divide the problem in two equations which sum would be the solution of the problem:
u(x,t)=v(x,t)+U(x)u(x,t)=v(x,t)+U(x)
kU(x)′′+c=0kU(x)″+c=0
U(x)=−cx22k+(2c0+c2k)xU(x)=−cx22k+(2c0+c2k)x
vt=kvxxvt=kvxx
Which I can solve and plot with my code. So, is there any way to plot the U and sum it to the plot of the second one over the time? thanks
Last edited by a moderator: