How to modify a value in code.
조회 수: 1 (최근 30일)
이전 댓글 표시
This has had me stumped all day. Any help is appreciated. I'm trying to do the following with my code. I want to generate a randomly values of ""p", that must be in limits of a and b and total sum of p in a row i.e p(:,1)+p(:,2)+p(:,3) must be equal to Demand plus PL. The value of PL is to be computed by the values of p by the formula.
clear all ; clc
Demand=300;
N=3;
a(1,1)=100; b(1,1)=600; %bounds on variable 1
a(1,2)=100; b(1,2)=400; %bounds on variable 2
a(1,3)=50; b(1,3)=200; %bounds on variable 3
x=a+(b-a).*rand(1,3);
T=x(:,1)+x(:,2)+x(:,3); %total
z=[x(:,1)./T(:,1) x(:,2)./T(:,1) x(:,3)./T(:,1)]; % Equlity constraint
p= z.*Demand;
Total= p(:,1)+p(:,2)+p(:,3); % Total must be equal to Demand + PL
f1=561+ 7.92.*p(:,1)+0.00156.*(p(:,1).^2); f2=310+ 7.85.*p(:,2)+0.00194.*(p(:,2).^2); f3=78+ 7.97.*p(:,3)+0.00482.*(p(:,3).^2); TC=f1+f2+f3;
PL= 10+p.^(1/4);
--> At the end I just found that sum(p) is equal to Demand as I made it in (p= z.*Demand) and it is not equal to PL+Demand that's the requirement. Please guide me in this regard.
댓글 수: 3
Roger Stafford
2014년 12월 17일
Thorsten asks a good question which you should pay attention to. What does the computation of 'TC' have to do with 'PL'? Your line
PL = 10+p.^(1/4);
produces a three-element vector, rather than the needed scalar, and 'TC' is never used. You need to clear up this point before a sensible answer to your question can be given. Please give us a precise formula for finding a scalar 'PL' that makes sense.
답변 (1개)
Sean de Wolski
2014년 12월 17일
댓글 수: 3
John D'Errico
2014년 12월 28일
편집: John D'Errico
2014년 12월 28일
Sean - randfixedsum assumes the points lie in a cube, not a hyper rectangle. The question here has lower and upper limits that differ for each variable. Note that the restriction for randfixed sum is
a <= x(i) <= b
as opposed to
a(i) <= x(i) <= b(i)
The latter is what is needed to solve this question.
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!