how to calculate the value of u(x,t)=exp(at+bx) for x=0 to 1 and t=0 to 1
5 次查看(过去 30 天)
显示 更早的评论
I want the numerical value of u for different value of x and t and want to plot u verus x and u verus t
0 个评论
回答(2 个)
Subhadra Mahanti
2016-2-8
You didn't mention values of a and b. So I am passing that as an argument here.
u_xt = @(x,t,a,b) exp(a*t+b*x); % Create a function handle
x=[0:0.1:1]; %NOTE: I chose the step-size here as 0.1
t=[0:0.1:1]; %NOTE: Since your boundary conditions for x and t are identical [0 1] the step size has to be same for both
a = 5; % (say)
b = 2; % (say)
result = u_xt(x,t,a,b);
plot(u_xt,x);
% If you want to plot both on the same figure
hold on;
plot(u_xt,t);
0 个评论
John BG
2016-2-8
Try this:
a0=1
b0=1
T0=1
step_x=.01
step_t=.01
L_t=T0/step_t
L_x=T0/step_x
a=a0*ones(1,L_t+1)
b=b0*ones(1,L_x+1)
[X,T]=meshgrid([0:step_x:T0],[0:step_t:T0])
U=exp(diag(a)*T+diag(b)*X)
surf(U) % visualize result
SU=surface(U) % create surface object
u_x_t=SU.ZData % u(x,t) you asking for is contained in SU.ZData
% u(x)
u_xt1=u_x_t(:,1) % to plot u(x) first fix t, for instance t=1
u_xt2=u_x_t(:,2) % u(x) for t=2
figure(2);plot(u_xt2);grid on
% u(t)
u_tx10=u_x_t(:,1) % to plot u(t) first fix x, for instance x=10
u_tx21=u_x_t(:,2) % u(t) for t=21
If you find this answer of any help to solve your question, please click on the thumbs-up vote link above, thanks in advance
John
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!