Plot a non homogeneous DPE -- Sum two plots in Matlab?

Your Name]In summary, to include the non-homogeneous term in your PDE equation and plot the solution, you need to modify the initial condition, define the non-homogeneous boundary conditions, and modify the code to incorporate the term. Once this is done, you should be able to run the code and plot the solution with the non-homogeneous term included. If you have any further questions, you can reach out for assistance.
  • #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.

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​
and 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
 
Last edited by a moderator:
Physics news on Phys.org
  • #2


Thank you for your question. It is indeed possible to include the non-homogeneous term in your code and plot the solution. Here are some steps you can follow:

1. Add the non-homogeneous term to your PDE equation in the code. It should look something like this:

ut = kuxx + cut + c

2. Modify the initial condition to include the non-homogeneous term. This can be done by adding the term to the existing initial condition function, like this:

ci = 'c0*(1-cos(pi*x)) + c'

3. Define the non-homogeneous boundary conditions in the code. This can be done by adding the term to the existing boundary condition functions, like this:

cca = 'c + 2*c0'
ccb = '2*c0'

4. Modify the code to incorporate the non-homogeneous term. This might involve changing the matrices and vectors used in the code, as well as the boundary conditions and initial conditions.

5. Run the code and plot the solution. You should now be able to see the solution with the non-homogeneous term included.

I hope this helps you plot the solution to your PDE. If you have any further questions, please let me know.
 

1. What is a non-homogeneous DPE?

A non-homogeneous DPE (differential partial equation) is a mathematical equation that involves both the dependent variable and its derivatives with respect to one or more independent variables, as well as a non-zero constant term. This constant term distinguishes it from a homogeneous DPE, which has a constant term of zero.

2. How do I plot a non-homogeneous DPE in Matlab?

To plot a non-homogeneous DPE in Matlab, you will need to define the equation using symbolic variables and functions. Then, you can use the "ezplot" function to plot the equation over a specified range of values for the independent variables. You may also need to specify initial conditions or boundary conditions depending on the specific DPE you are working with.

3. What are the benefits of plotting a non-homogeneous DPE in Matlab?

Plotting a non-homogeneous DPE in Matlab allows you to visualize the behavior of the dependent variable over a range of values for the independent variables. This can help you better understand the solutions to the DPE and identify any critical points or regions of interest.

4. Can I sum two plots of non-homogeneous DPEs in Matlab?

Yes, you can sum two plots of non-homogeneous DPEs in Matlab. This can be useful for comparing the behavior of two different DPEs or for visualizing the combined effect of two independent variables on the dependent variable.

5. Are there any limitations to plotting non-homogeneous DPEs in Matlab?

One limitation of plotting non-homogeneous DPEs in Matlab is that the solutions may become unstable or inaccurate for certain boundary conditions or large values of the independent variables. It is important to carefully choose the range of values and boundary conditions to ensure accurate and reliable plots.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Differential Equations
Replies
7
Views
392
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Differential Equations
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
6
Views
2K
  • Differential Equations
Replies
23
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Back
Top