Calculating integral in MATLAB

5 vues (au cours des 30 derniers jours)
Syed Izhar Ul Haq
Syed Izhar Ul Haq le 23 Mar 2021
Commenté : David Hill le 24 Mar 2021
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

Réponse acceptée

David Hill
David Hill le 23 Mar 2021
Modifié(e) : David Hill le 23 Mar 2021
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 commentaires
Syed Izhar Ul Haq
Syed Izhar Ul Haq le 24 Mar 2021
Modifié(e) : Syed Izhar Ul Haq le 24 Mar 2021
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 le 24 Mar 2021
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)));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by