How to write this summation function?

5 Ansichten (letzte 30 Tage)
Felipe Gonzalez
Felipe Gonzalez am 31 Mär. 2017
Kommentiert: Image Analyst am 1 Apr. 2017
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 31 Mär. 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 Kommentare
Felipe Gonzalez
Felipe Gonzalez am 1 Apr. 2017
Sorry. There are 2 components. But I need to compute 10 times.
Image Analyst
Image Analyst am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by