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

3 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by