I need to run a surface diagram for variables using any 2 parameters. The following is the code for 2D plots. Please help me to run surf plot in MATLAB.
이전 댓글 표시
Error that appear when run the code:
Error in proj (line 20)
surf(a_vec,t,squeeze(X(:,1,:))) ;
Code below:
options = odeset('RelTol',1e-6,'Stats','on');
%initial conditions
Xo = [0.5;0.7;2];
% Choose parameters t and a?
tspan =linspace(0,100);
a_vec = 0.01:0.005:0.03;
for idx = 1:numel(a_vec)
% Collect all X values into a 3D matrix. Additional parameters to
% TestFunction can be added after ode45 options
[t,X(:,:,idx)] = ode45(@TestFunction,tspan,Xo,options,a_vec(idx));
end
% figure
% plot(t, X(:,1), 'red')
% hold on % keeps all three plots on the axes
% plot(t, X(:,2), 'blue')
% plot(t, X(:,3), 'red')
figure
surf(a_vec,t,squeeze(X(:,1,:))) ;
% Squeeze removes dimensions of size 1, turning this slice into a 2d matrix
function [dx_dt]= TestFunction(~,x,a)
r=0.05; k=0.1; %a=0.02;
m=0.02; b=0.2; eta=0.06; h=1;
dx_dt(1)=r.*x(1).*(1-(x(1)./k))-a.*x(1).*x(3)+x(3).*eta;
dx_dt(2)=a.*x(1).*x(3)-m.*x(2)-b.*x(2)+h.*eta;
dx_dt(3)=b.*x(2)-eta.*x(3)-r.*x(1);
dx_dt = dx_dt';
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

