Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to fix this error?

1 vue (au cours des 30 derniers jours)
sing lai
sing lai le 14 Mar 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
function [u,x,t] = wave(a,xf,T,f,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
%solve_wave
a = 1, L=0.64, h=0.005;
d = input('d = ');
if 'x' >= 0 && 'x' <= d
f = h*'x'./d;
elseif 'x' >= d && 'x' <= L
f = h*(L-'x')./(L-d);
end
i1t0 = inline('0'); %initial condition
bx0 = inline('0'); bxf = inline('0'); %boundary condition
xf = 1; M = 20; T = 2; N = 50;
dx = xf/M; x = [0:M]'*dx; %space step size
dt = T/N; t = [0:N]*dt; %time step size
for i = 1:M + 1, u(i,1) = f(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));
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);
end
figure(1), clf
mesh(t,x,u)
figure(2), clf
xlabel('x')
ylabel('u')
for n = 1:N %dynamic picture
plot(x,u(:,n)), axis([0 xf -0.3 0.3]), pause(0.2)
end
The error is: ??? Input argument "f" is undefined.
Error in ==> pdehypwave at 24 for i = 1:M + 1, u(i,1) = f(x(i));
How to fix this error?Thanks!
  1 commentaire
Walter Roberson
Walter Roberson le 14 Mar 2014
Exactly how are you running the function?

Réponses (0)

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by