Error in ODE arguments

조회 수: 3 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by