Question
Need help solving it using matlab with for loop
Objective: Solve the wave equation numerically using finite difference methods with both dirichlet and neumann conditions. Co
0 0
Add a comment Improve this question Transcribed image text
Answer #1

close all

clear
clc

m = 0;
x = 0:0.2:1;
t = 0:0.01:0.5;

sol = pdepe(m,@pdefun,@icfun,@bcfun,x,t);
u = sol(:,:,1);

surf(x,t,u)
title('Solution of PDE')
xlabel('x'), ylabel('t'), zlabel('u')

% Error
[X,T] = meshgrid(x,t);
ua = exp(-(pi^2) T) . sin(pi*X);
error = abs(u - ua);
En = norm(error, Inf);
disp('En ='), disp(En)

function [c,f,s] = pdefun(x,t,u,DuDx)
c = 1;
f = DuDx;
s = 0;
end

function u0 = icfun(x)
u0 = sin(pi*x);
end

function [pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = 0;
qr = 1;
end

Output:

En =
1.434450078921155

Plot:

Solution of PDE 0.8 0.6 0.4 0.2 0.6 0.4 0.8 0.6 0.2 0.4 0.2

Add a comment
Know the answer?
Add Answer to:
Objective: Solve the wave equation numerically using finite difference methods with both dirichle...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT