I get the answer for my question but i ddnt understand where you have enter the function.If u can explain me the coding for this

2 views (last 30 days)
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

Answers (1)

Star Strider
Star Strider on 9 Feb 2016
Here you go:
a = -1; % Create Data
b = 5; % Create Data
u = @(x,t) exp(a.*t+b.*x); % Create Anonymous Function From Your Function
x = linspace(0, 1, 50); % 50-Element Vector For ‘x’
t = linspace(0, 1, 50); % 50-Element Vector For ‘t’
[X,T] = meshgrid(x,t); % Create Grids For ‘x’ & ‘t’
Z = u(X,T); % Compute Result
figure(1)
surf(X, T, Z)
xlabel('x');
ylabel('t')
zlabel('u(x,t) = exp(a\cdott + b\cdotx)')
grid on
It is necessary to create an anonymous function from your function (see the section under Function Basics for Anonymous Functions, and using vectorised operations, see Array vs. Matrix Operations), then create grids for ‘t’ and ‘x’, and evaluate them as ‘Z’. Then plot them.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!