how to calculate the value of u(x,t)=exp(at+bx) for x=0 to 1 and t=0 to 1

5 ビュー (過去 30 日間)
YOGESHWARI PATEL
YOGESHWARI PATEL 2016 年 2 月 8 日
回答済み: John BG 2016 年 2 月 8 日
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

回答 (2 件)

Subhadra Mahanti
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);

John BG
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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by