How to write this summation function?

2 views (last 30 days)
Hi. I need to write this summation on Matlab and I don't know how.
T_new = ∑x·Tsat
x was written as a vector:
x = linspace (0,1,10)
And Tsat:
for i=1:comp;
Tsat(i)=(C2(i)/(C1(i)-(ln(P)))-C3(i));
end
C1, C2, C3 are constants. There are 2 components (comp). But I need to compute 10 times. At the end, I will plot my code.

Accepted Answer

Image Analyst
Image Analyst on 31 Mar 2017
Where is Tsat in the formula? All I see is T_new and T. And x has 10 elements while Tsat has comp elements. If comp is not 10, then Tsat and x have different number of elements, so that means T is not in the sum, just x is. So the sum could be written as
T_new = sum(x) - T
  2 Comments
Felipe Gonzalez
Felipe Gonzalez on 1 Apr 2017
Sorry. There are 2 components. But I need to compute 10 times.
Image Analyst
Image Analyst on 1 Apr 2017
I don't know what that means. sum() will sum all 10 elements of x. So now the first equation, taking your edit into account, becomes this:
T_new = sum(x) - Tsat;
I don't know why you need to do the second chunk of code (the loop) 10 times because it's no different after the 10th time than after the first time, but anyway...put it in a loop:
for k = 1 : 10 % Do the inner loop over "i" 10 times.
for i=1:comp;
Tsat(i)=(C2(i)/(C1(i)-(ln(P)))-C3(i));
end
end
Again Tsat is the same after each iteration of k.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!