How to fix the error?

조회 수: 1 (최근 30일)
sing lai
sing lai 2014년 2월 25일
편집: Niklas Nylén 2014년 2월 25일
function [u,x,t] = wave(a,xf,T,it0,i1t0,bx0,bxf,M,N)
%solve a u_xx = u_tt for 0<=x<=xf, 0<=t<=T
% Initial Condition: u(x,0) = it0(x), u_t(x,0) = i1t0(x)
% Boundary Condition: u(0,t)= bx0(t), u(xf,t) = bxf(t)
% M = # of subintervals along x axis
% N = # of subintervals along t axis
dx = xf/M; x = [0:M]*dx;
dt = T/N; t = [0:N]*dt;
for i = 1:M + 1, u(i,1) = it0(x(i)); end
for k = 1:N + 1
u([1 M + 1],k) = [bx0(t(k)); bxf(t(k))];
end
r = a*(dt/dx)^ 2; r1 = r/2; r2 = 2*(1 - r);
u(2:M,2) = r1*u(1:M - 1,1) + (1 - r)*u(2:M,1) + r1*u(3:M + 1,1) ...
+ dt*i1t0(x(2:M)); %Eq.(9.3.6)
for k = 3:N + 1
u(2:M,k) = r*u(1:M - 1,k - 1) + r2*u(2:M,k-1) + r*u(3:M + 1,k - 1)...
- u(2:M,k - 2); %Eq.(9.3.3)
end
%solve_wave
a = 1;
it0 = inline(x.*(1-x),x); i1t0 = inline(0); %(E9.4.2a)
bx0t = inline(0); bxft = inline(0); %(E9.4.2b)
xf = 1; M = 20; T = 2; N = 50;
[u,x,t] = wave(a,xf,T,it0,i1t0,bx0t,bxft,M,N);
figure(1), clf
mesh(t,x,u)
figure(2), clf
for n = 1:N %dynamic picture
plot(x,u(:,n)), axis([0 xf -0.3 0.3]), pause(0.2)
end
The error is ?? Error: File: wave.m Line: 22 Column: 14 The input character is not valid in MATLAB statements or expressions.
But, after I erase the ' symbol, the error become ??? Input argument "xf" is undefined.
Error in ==> wave at 7 dx = xf/M; x = [0:M]*dx;
Anyone can tell me what's wrong for this code?thanks!

채택된 답변

Niklas Nylén
Niklas Nylén 2014년 2월 25일
편집: Niklas Nylén 2014년 2월 25일
In your pasted code it seems like you have used the slightly tilted ’ instead of ' for the apostrophe (or whatever the correct name of it is). Replace them with '
  댓글 수: 1
sing lai
sing lai 2014년 2월 25일
Thanks a lot,i got it~

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by