10 views (last 30 days)

I am trying to generate equations of motion for Spring mass (damper) system consisting of N blocks. I want to write such a function that automatically creates equations of motion(that fills these matrices A,B,C) just by passing a value of number of masses in a function input arguement. This is what I want ideally. I know the pattern for equation of motion. My system matrix A is something like

[ -2k k 0 0... 0(n);

k -3k k 0.... 0(n);

0 k -3k k 0... 0(n);

0 0 k -3k k 0 .... 0(n);

.. 0(n);

.. 0(n);

0 0............. k -2k ]

where k is stiffness of the spring. This matrix has some kind of uniform pattern as you can see. How can I write a function to this?

Dhananjay Kumar
on 4 Dec 2019

I think this should be very simple (Writing the generalized matrix in the image). You just need to know array indexing and for loop in MATLAB.

Take as input, a k vector, and a constant n.

For n>=3, loop through i= 2 to n-1, and update the matrix values according to the values in the image (you will need to write just 3 assgnment statements inside the for loop for the three values). For i=1 and i=n update the matrix values outside the loop (total 4 assignment statement).

For n<3, you can update the values in the matrix without loop.

Please first try yourself and then post your doubts here.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773120

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773120

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773123

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773123

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773125

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/494142-how-can-i-get-system-matrix-a-b-and-c-for-my-state-space-system-of-spring-mass-damper-system-of-n-bl#comment_773125

Sign in to comment.