for loop question (column vector?)

조회 수: 1 (최근 30일)
Alexander Guillen
Alexander Guillen 2022년 3월 17일
답변: David Hill 2022년 3월 17일
I would like to solve the following equation using a for loop. I am able to perform a foor loop to calculate x2. However, when I get to the main equation, I have a problem because RT_w is a column vector. I am able to solve the equation similar as I would solve it in excel. But I want to implement a for loop . So in the end I should have three columns, one column when RT/W = 0.4 and so on.
RT_W = [0.4;0.5;0.6];
x1 = 0:0.01:1;
% x2 = 1-x1;
for k = 1:length(x1)
x2(k) = 1 - x1(k);
end

채택된 답변

David Hill
David Hill 2022년 3월 17일
Of course you will get NAN for log(0)
RT_W = [0.4;0.5;0.6];
x1 = 0:0.01:1;
x2=1-x1;
for k=1:length(RT_W)
dG_W(k,:)=RT_W(k)*(x1.*log(x1)+x2.*log(x2))+x1.*x2;
end

추가 답변 (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