How to plot function x(2)=-1/2*x(1)+t?
4 views (last 30 days)
Show older comments
clc;
clear;
close;
x1=3+3/8;
u=8;
teta(1)=0;
%teta(u+2)=0.2;
for i=1:u
teta(i+1)=i/5;
end
for j=1:1
for k=1:u
%initial_func=[x1,x2];
[t,x] = ode45(@IJP4,[teta(k):0.0001:teta(k+1)], x1(j));%
n=length(t);
%disp(size(x));
x1(j)=x(n,1)+4*x(n,1);
hold on
%view(30,15);
x(2)=-1/2*x(1)+t;
hold on
figure(1)
subplot(2,1,1);
plot(t,x(:,2),'color','g','Linewidth',1.2);
xlabel('\bf t'); ylabel('$$z$$','interpreter','latex','fontsize',16); zlabel('\bf \psi_2');
grid on
hold on
subplot(2,1,2);
plot(t,x(:,1),'color','g','Linewidth',1.2);
xlabel('\bf t'); ylabel('$$y$$','interpreter','latex','fontsize',16); zlabel('\bf \psi_3');
grid on
hold on
figure(2)
plot3(t,x(:,1),x(:,1),'g');
xlabel('$$t$$','interpreter','latex','fontsize',16)
%ylabel('\phi_{2}','fontsize',16)
ylabel('$$z$$','interpreter','latex','fontsize',16)
zlabel('$$y$$','interpreter','latex','fontsize',16);
grid on
hold on
end
end
function dx=IJP4(t,x)
dx=zeros(1,1); % создает нулевой вектор-столбец
dx(1)=-3/2*x(1)-6*x(1);
end
0 Comments
Accepted Answer
Cris LaPierre
on 9 May 2025
Moved: Matt J
on 10 May 2025
Did you mean to assign the result of -1/2*x(1)+t; to the second column of x?
x(:,2)=-1/2*x(1)+t;
If so, then the code runs at least. I have no idea if this is what you expect.
clc;
clear;
close;
x1=3+3/8;
u=8;
teta(1)=0;
%teta(u+2)=0.2;
for i=1:u
teta(i+1)=i/5;
end
for j=1:1
for k=1:u
%initial_func=[x1,x2];
[t,x] = ode45(@IJP4,[teta(k):0.0001:teta(k+1)], x1(j));%
n=length(t);
%disp(size(x));
x1(j)=x(n,1)+4*x(n,1);
hold on
%view(30,15);
x(:,2)=-1/2*x(1)+t; % Change here to assign output to column 2
hold on
figure(1)
subplot(2,1,1);
plot(t,x(:,2),'color','g','Linewidth',1.2);
xlabel('\bf t'); ylabel('$$z$$','interpreter','latex','fontsize',16); zlabel('\bf \psi_2');
grid on
hold on
subplot(2,1,2);
plot(t,x(:,1),'color','g','Linewidth',1.2);
xlabel('\bf t'); ylabel('$$y$$','interpreter','latex','fontsize',16); zlabel('\bf \psi_3');
grid on
hold on
figure(2)
plot3(t,x(:,1),x(:,1),'g');
xlabel('$$t$$','interpreter','latex','fontsize',16)
%ylabel('\phi_{2}','fontsize',16)
ylabel('$$z$$','interpreter','latex','fontsize',16)
zlabel('$$y$$','interpreter','latex','fontsize',16);
grid on
hold on
end
end
function dx=IJP4(t,x)
dx=zeros(1,1); % создает нулевой вектор-столбец
dx(1)=-3/2*x(1)-6*x(1);
end
More Answers (0)
See Also
Categories
Find more on Subplots 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!

