How to plot function x(2)=-1/2*x(1)+t?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cris LaPierre
2025년 5월 9일
이동: Matt J
2025년 5월 10일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


