How to plot function x(2)=-1/2*x(1)+t?

조회 수: 4 (최근 30일)
Nauryzbay
Nauryzbay 2025년 5월 9일
이동: Matt J 2025년 5월 10일
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
Unable to perform assignment because the left and right sides have a different number of elements.
function dx=IJP4(t,x)
dx=zeros(1,1); % создает нулевой вектор-столбец
dx(1)=-3/2*x(1)-6*x(1);
end

채택된 답변

Cris LaPierre
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
  댓글 수: 1
Nauryzbay
Nauryzbay 2025년 5월 10일
이동: Matt J 2025년 5월 10일
Thank you so much. You've been very helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by