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
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2016-2-9
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!