How to solve this question in MATLAB?
1 view (last 30 days)
Show older comments
I have tried this question manually as well as in MATLAB but the value of U(x,t) not match with my manual calculation answer. I dont know where I make the mistake.
%Evaluate BC
dx = 0.25;
X = 0:dx:1;
dt = 0.1;
t = 0:dt:1;
h = 1/(length(X)-1) ; %step size
u = zeros(length(t),length(X));
for j = 1:length(t)
for i=1:length(X)
u(j,i) = exp((-pi*j)/4)*sin((pi*i)/2);
end
end
disp([X' u'])

1 Comment
Jiri Hajek
on 11 Jan 2023
Hi, in your expression, you are not using as inputs x(i) and t(j), but just the indices...
Accepted Answer
KSSV
on 11 Jan 2023
dx = 0.25 ;
dt = 0.1 ;
x = 0:dx:1 ;
t = 0:dt:1 ;
[x,t] = meshgrid(x,t) ;
U = exp(-pi*t/4).*sin(pi*x/2) ;
surf(x,t,U)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!