matlab pdepe求解偏微分方程
4个回答
展开全部
function pdex1
m=0;
x=linspace(0,1,20);
t=linspace(0,2,5);
sol=pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u=sol(:,:,1);
surf(x,t,u)
figure
plot(x,u(end,:))
function[c,f,s]=pdex1pde(x,t,u,DuDx)
c=pi^2;
f=DuDx;
s=u^2;
function u0=pdex1ic(x)
u0=sin(pi*x);
function [pl,ql,pr,qr]=pdex1bc(x1,u1,xr,ur,t)
pl=u1;
ql=0;
pr=pi*exp(-t);
qr=1;
m=0;
x=linspace(0,1,20);
t=linspace(0,2,5);
sol=pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u=sol(:,:,1);
surf(x,t,u)
figure
plot(x,u(end,:))
function[c,f,s]=pdex1pde(x,t,u,DuDx)
c=pi^2;
f=DuDx;
s=u^2;
function u0=pdex1ic(x)
u0=sin(pi*x);
function [pl,ql,pr,qr]=pdex1bc(x1,u1,xr,ur,t)
pl=u1;
ql=0;
pr=pi*exp(-t);
qr=1;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
%这个问题和Matlab的示例问题差不多,只要对c,f,s修改一下,同时有一点,t不能从0开始,不然有bug,所以设置了一个很小的数开始,结果都是差不多的
function slove_pdepe
m = 0;
x = linspace(0,1,20);
t = linspace(8e-32,2,5);
sol = pdepe(m,@pdefun,@icfun,@bcfun,x,t);
u = sol(:,:,1);
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
function [c,f,s] = pdefun(x,t,u,DuDx)
c = pi^2.*sin(x).*t;
f = t.*DuDx;
s = u.*x;
function u0 = icfun(x)
u0 = sin(pi*x);
function [pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
function slove_pdepe
m = 0;
x = linspace(0,1,20);
t = linspace(8e-32,2,5);
sol = pdepe(m,@pdefun,@icfun,@bcfun,x,t);
u = sol(:,:,1);
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
function [c,f,s] = pdefun(x,t,u,DuDx)
c = pi^2.*sin(x).*t;
f = t.*DuDx;
s = u.*x;
function u0 = icfun(x)
u0 = sin(pi*x);
function [pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-04-15
展开全部
先标记下,有空在帮你编写程序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function pdex1
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = 0;
function u0 = pdex1ic(x)
u0 = sin(pi*x);
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = 0;
function u0 = pdex1ic(x)
u0 = sin(pi*x);
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
追问
直接 从help pdepe 复制的,不是问题答案
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询