フィルターのクリア

How to assign a vector to multiple values.

3 ビュー (過去 30 日間)
Jesse Crotts
Jesse Crotts 2018 年 12 月 8 日
編集済み: Jesse Crotts 2018 年 12 月 8 日
I have these lines of code:
function f = trick(t,x,M,K)
f = zeros(4,1);
f(1) = x(2);
f(2) = x(3);
Minvneg = -inv(M);
[f(3),f(4)] = Minvneg*K*[x(4) x(5)]';
I'm using this inside of a function called within the ode23 function where M and K are 2x2 matrices. the result of
Minvneg*K*[x(4) x(5)]'
should give a 2x1 column vector which I need to assign to f(3) and f(4) respectively.
I have tried doing this multiple ways except for making the matrix multiplication happen within double for loops which is terrable.
What is the best way to assign these values.
I think this would be very similar to doing this and it not working.
[a b] = [1 2]
One thing I tried but didn't work was:
delta=Minvneg*K*[x(4) x(5)]';
f(3)=delta(1);
f(4)=delta(2);
This just doesn't work within the ode23 function
If it helps, here is the code I am using to call this function:
clc; clear
figure
time = (0:.001:22.5)';
M = [1 2; 3 4];
K = [5 6; 7 8];
x0 = [0;0;0;0]; %[position,velocity]
[t1,x]=ode23(@(t1,x) trick(t1,x,M,K), time, x0);
plot(t1,x(:,1));
xlabel('Time(sec)');
ylabel('Displacement');
title('Stepped Response(Underdamped)');

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by