Error in ODE arguments

10 ビュー (過去 30 日間)
Alexander Salas
Alexander Salas 2021 年 12 月 7 日
編集済み: Jan 2021 年 12 月 7 日
Hello,
I am a newbie at MATLAB and I am trying to get a forcing function to work. I can get it to work without the F(t)/M but once I add it, it says error in ODE arguments:
clear
close all
% System parameters
m1 = 2000; Icg = 2500; % kg
c1 = 3000; c2 = 3000; % kg/s
k1 = 30000; k2 = 30000; % N/m
l1 = 1; l2 = 1.5;
M = [m1 0
0 Icg];
C = [(c1+c2) (c1*l1-c2*l2)
(c1*l1-c2*l2) ((c2*l2^2)+(c1*l1^2))];
K = [(k1+k2) (k1*l1-k2*l2)
(k1*l1-k2*l2) ((k2*l2^2)+(k1*l1^2))];
Br = [k1 k2
k1*l1 -k2*l2];
Brdot = [c1 c2
c1*l1 -c2*l2];
r = [.015 .015]';
r1 = [.086 .086]';
F = @(t) Br*r + Brdot*r1;
% Time grid
t0 = 0; tf = 10; dt = 0.01; t = t0:dt:tf;
% Set initial state and integrate equations of motion
s0 = [1 1 0 0]';
f = @(t,s) [s(3);s(4);(F(t)/M)*-C/M*[s(3) s(4)]'-K/M*[s(1) s(2)]'];
[t,s] = ode45(f,t,s0);
% Plot system motion
figure
subplot(211),plot(t,s(:,1),t,s(:,2),'LineWidth',2)
grid minor
legend('x1','x2')
xlabel('Time (s)')
ylabel('Displacements (m)')
title('System Dynamic Response')
subplot(212),plot(t,s(:,3),t,s(:,4),'LineWidth',2)
grid minor
legend('v1','v2')
xlabel('Time (s)')
ylabel('Velocity (m/s)')
  4 件のコメント
Alexander Salas
Alexander Salas 2021 年 12 月 7 日
Jan
Jan 2021 年 12 月 7 日
This is no valid Matlab syntax:
M = [m1 0
0 Icg];
The blank line in the code is not allowed. Therefore I asked you to remove the blank lines.

サインインしてコメントする。

採用された回答

Alan Stevens
Alan Stevens 2021 年 12 月 7 日
I suspect you mean like this (notice the way M divides, using the back-slash):
% Numerical solution of IVP
% M*xddot + C*xdot + K*x = F(t) with x(0) = x0 and xdot(0) = v0
% System parameters
m1 = 2000; Icg = 2500; % kg
c1 = 3000; c2 = 3000; % kg/s
k1 = 30000; k2 = 30000; % N/m
l1 = 1; l2 = 1.5;
M = [m1 0
0 Icg];
C = [(c1+c2) (c1*l1-c2*l2)
(c1*l1-c2*l2) ((c2*l2^2)+(c1*l1^2))];
K = [(k1+k2) (k1*l1-k2*l2)
(k1*l1-k2*l2) ((k2*l2^2)+(k1*l1^2))];
Br = [k1 k2
k1*l1 -k2*l2];
Brdot = [c1 c2
c1*l1 -c2*l2];
r = [.015 .015]';
r1 = [.086 .086]';
F = @(t) (Br*r) + (Brdot*r1);
% Time grid
t0 = 0; tf = 10; dt = 0.01; t = t0:dt:tf;
% Set initial state and integrate equations of motion
s0 = [1 1 0 0]';
f = @(t,s) [s(3);s(4);M\F(t)-M\C*[s(3) s(4)]'-M\K*[s(1) s(2)]']; %%%%%%%%%%%%%%
[t,s] = ode45(f,t,s0);
% Plot system motion
figure
subplot(211),plot(t,s(:,1),t,s(:,2),'LineWidth',2)
grid minor
legend('x1','x2')
xlabel('Time (s)')
ylabel('Displacements (m)')
title('System Dynamic Response')
subplot(212),plot(t,s(:,3),t,s(:,4),'LineWidth',2)
grid minor
legend('v1','v2')
xlabel('Time (s)')
ylabel('Velocity (m/s)')
  1 件のコメント
Jan
Jan 2021 年 12 月 7 日
編集済み: Jan 2021 年 12 月 7 日
A further simplification:
f = @(t,s) [s(3); s(4); M \ F(t) - M \ C * s(3:4) - M \ K * s(1:2)];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by