How to write this summation function?

1 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2017-3-31
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 个评论
Felipe Gonzalez
Felipe Gonzalez 2017-4-1
Sorry. There are 2 components. But I need to compute 10 times.
Image Analyst
Image Analyst 2017-4-1
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by