Help with for loop
이전 댓글 표시
Need to display the two graphs in the question. I am having a hard time with the for loop.
답변 (1개)
Walter Roberson
2022년 3월 11일
You have a for i loop 1 to the number of elements in X
Inside that loop you have
for i=1,2;
Notice that you are reusing the variable name i, interfering with i from the outer loop.
Notice that you used 1,2 not 1:2
댓글 수: 8
Angelina Encinias
2022년 3월 11일
Walter Roberson
2022년 3월 11일
Y=(x(i)*L(i)*(P(i))/P
1 2 1 2 1 2 3 21
You have one more ( than you have )
You also have a complete vector on the right side of the / operator. The / is very unlikely to be the operation you are thinking it is. A/B is similar to innerProduct(A, pinv(B))
What size are you expecting Y to come out as?
You are overwriting all of Y in each iteration.
Angelina Encinias
2022년 3월 11일
Getting P from x1 (thus the liquid line of the first graph) should be no problem (can you write down the formula ?).
Thus getting y1 from x1 should also be no problem (second graph) (can you write down the formula ?).
The only thing for which you have to use "fzero" is to get P from y1 (vapour line of the first graph) (can you write down the equation you have to solve ?).
Angelina Encinias
2022년 3월 11일
Is there an error for how I wrote them?
Yes, e.g. it makes no sense trying to find a zero of the equation defined in "fun".
Don't start coding before you have a strategy how to get the result.
I suggest you try to answer the three questions (here or for yourself).
Once you have the answers, coding will be simple.
This may sound arrogant and educational, but it's the truth.
Angelina Encinias
2022년 3월 11일
a = 1.4106;
b = 1.3438;
Pvap1 = 1.1541;
Pvap2 = 0.7609;
gamma1 = @(x1) exp(a./(1+(a/b)*x1./(1-x1)).^2);
gamma2 = @(x2) exp(b./(1+(b/a)*x2./(1-x2)).^2);
x1 = 0:0.01:1;
x2 = 1 - x1;
P = x1.*gamma1(x1)*Pvap1 + x2.*gamma2(x2)*Pvap2;
y1 = x1.*gamma1(x1)*Pvap1./P;
figure(1)
plot(x1,P)
hold on
plot(y1,P)
figure(2)
plot(x1,y1)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!