-2

integral in question

How can I calculate the integral as shown in the screen shot, where j1 is a 1x3 matrix and j2 is also a 1x3 matrix, while g1 is a 300x3 matrix and also g2 is a 300x3 matrix.

In the screen shot the '.' represents the dot product.

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
  • I guess size of j1 and j2 must is 3x1? And need calculate numerical integral? – geoinformatic Mar 23 '21 at 21:51
  • 1
    Welcome to SO! The way it generally works here is that you show what you've tried (post some code) and say what didn't work. This isn't a place to do you homework without you showing effort. See [ask]. – Justin Mar 23 '21 at 21:59
  • thank you for the reply @Justin I have updated the question, – Izhar Ulhaq Mar 24 '21 at 20:01
  • thank you for the reply @geoinformatic I have updated the question what would you suggest now ? – Izhar Ulhaq Mar 24 '21 at 20:02

1 Answers1

0

This is my solution (if I understood right your task):

t = g1(:,1); % time values
integrand = g1(:,2:4)*j1' - g2(:,2:4)*j2'; % symbol " ' " mean transpose
 
alfa_gyro = [];

for i = 2:length(t)
alfa_gyro(i) = trapz(t(1:i), integrand(1:i));
end

result = [t, alfa_gyro'];
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • Answers are better if they explain the solution, rather than just give code. – Cris Luengo Mar 28 '21 at 22:26
  • The code I provided is very simple and understanding. Original variable names were used. If @Izhar Ulhaq will need some additional explanations, then I will provide it. *** 2 moderator - I don't see any reasons was edited my post. – geoinformatic Mar 29 '21 at 06:54
  • I removed the first sentence because it is extraneous to the answer. Stack Overflow is a **curated** collection of questions and answers for the benefit of the millions of people looking for an answer to their problem, not specifically for the person that posted the question. This is why it is important for the answer to address the specific question, and not be a part of a conversation. [People prefer it if distractions are removed from posts](https://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – Cris Luengo Mar 29 '21 at 15:03