how to calculate the value of u(x,t)=exp(at+bx) for x=0 to 1 and t=0 to 1
Show older comments
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
Answers (2)
Subhadra Mahanti
on 8 Feb 2016
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
on 8 Feb 2016
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
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!