Calculating integral in MATLAB

1 回表示 (過去 30 日間)
Syed Izhar Ul Haq
Syed Izhar Ul Haq 2021 年 3 月 23 日
コメント済み: David Hill 2021 年 3 月 24 日
how can I calculate the integral as shown in the screen shot. where j1 is of 1x3 matrix and j2 is also 1x3 matrix. while g1 is 300x3 matrix and also g2 is 300x3 matrix.
in the screen shot the '.' represents the dot product. your suggestion and help would be highly appreciated

採用された回答

David Hill
David Hill 2021 年 3 月 23 日
編集済み: David Hill 2021 年 3 月 23 日
I am assuming each row of g1 and g2 is going from T=0 to t; otherwise you will have to describe the functions g1 and g2 and how they relate to T (since the integration is with respect to it). I assume you can treat the integration as a summation.
dT=t/300;%not sure what t is and I assume the change is consistent point to point
AlphaGyr=dT*(dot(g1,repmat(j1,300,1))-dot(g2,repat(j2,300,1)));%dot is just sum(g1.*repmat(j1,300,1))
  2 件のコメント
Syed Izhar Ul Haq
Syed Izhar Ul Haq 2021 年 3 月 24 日
編集済み: Syed Izhar Ul Haq 2021 年 3 月 24 日
thanks for the reply.
Actually g1 and g2 are 300x4 matrix where 1st row is of 't'. and 1st row has t = 200 and 2nd row has 300 and so on till 300th row has 60000 value.
So, g1 and g2 is actually dependent on 't'.
if we take it as summation then would this be correct ?
Alpha_gyro = 0;
for i = 1:300
Alpha_gyro_function =(dot(g1(1,2:4),j1) - dot(g2(i,2:4),j2));
Alpha_gyro = Alpha_gyro + Alpha_gyro_function;
end
So, it gives output as 1 number. But now i am confused what would be the value of 'Alpha_gyro(t)' with respect to 't' . i.e, 'Alpha_gyro' should also be the matrix of 300x1, right ? because it is dependent on 't'
for that purpose would this be correct ?
Alpha_gyro = zeros(300,1)
for i = 1:300
Alpha_gyro_function =(dot(g1(1,2:4),j1) - dot(g2(i,2:4),j2));
Alpha_gyro(i) = Alpha_gyro(i) + Alpha_gyro_function;
end
But then, As we know integration has value from 0 to the new value of 't" so each value should be the sum of previous value in the new matrix.
So then I added this , Can you please guide if i am doing it right ?
Alpha_gyro = zeros(300,1);
Alpha_gyro_function_old =0 ;
for i = 1:300
Alpha_gyro_function =(dot(g1(1,2:4),G_upd_j1) - dot(g2(i,2:4),G_upd_j2));
Alpha_gyro_function_old = Alpha_gyro_function_old + Alpha_gyro_function;
Alpha_gyro(i) = Alpha_gyro(i) + Alpha_gyro_function_old;
end
David Hill
David Hill 2021 年 3 月 24 日
The dot product of a matrix does the sumation automatically so you don't need a loop. You just need to create same size matrix out of j1 and j2 as g2 and g2 using repmat. Below should work. Yes the final answer will be 1x300.
dT=100;
AlphaGyr=dT*(dot(g1,repmat(j1,300,1))-dot(g2,repat(j2,300,1)));

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

その他の回答 (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