24小时热门版块排行榜    

查看: 1751  |  回复: 1

公元19782012

木虫 (小有名气)

[求助] 一维一阶波动方程的迎风差分

请各位看看,下面是一维一阶波动方程的迎风差分,MATLAB程序,数值解总是出错。没多少金币,见谅

clear all;
clc;
%数值解(单边差分迎风格式)
a=0;
b=1;
c=1;
T=1;
ngrid=[20 501];
xspan=[a b];
tspan=[0 T];
m=ngrid(1);
n=ngrid(2);
ox=range(xspan)/m;
ot=range(tspan)/n;
r=c*ot/ox;
if r>1
    error;
end
for i=1:m+1                 %初始条件
    u(i,1)=sin((i-1)*ox);
end
for j=1:n+1                 %边界条件
    u(1,j)=sin((j-1)*ot);
    u(m+1,j)=sin((m)*ox+(j-1)*ot);
end
for j=1:n                   %数值解(单边差分迎风格式)
    for i=2:m
        u(i,j+1)=(1+r)*u(i,j)-r*u(i-1,j);
    end
end
%精确解

for j=1:n+1                 %精确解
    for i=1:m+1
        u1(i,j)=sin((i-1)*ox+(j-1)*ot);
    end
end
x=0x:range(xspan);
t=0t:range(tspan);
subplot(2,2,1)
plot(x,u(:,n/4),x,u1(:,n/4),'r')
title('n=10时刻')
grid on
subplot(2,2,2)
plot(x,u(:,n/2),x,u1(:,n/2),'r')
title('n=30时刻')
grid on
subplot(2,2,3)
plot(x,u(:,n*3/4),x,u1(:,n*3/4),'r')
title('n=40时刻')
grid on
subplot(2,2,4)
plot(x,u(:,n+1),x,u1(:,n+1),'r')
title('n时刻')
grid on
回复此楼
银样蜡枪头
已阅   关注TA 给TA发消息 送TA红花 TA的回帖

公元19782012

木虫 (小有名气)

人真少, 我自己解决了,是波动速度的正负和差分格式不匹配。想搞数值分析的可以一起交流
银样蜡枪头
2楼2014-12-28 19:48:16
已阅   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 公元19782012 的主题更新
信息提示
请填处理意见