How to modify a value in code.

1 回表示 (過去 30 日間)
Zahid Iqbal Rana
Zahid Iqbal Rana 2014 年 12 月 17 日
編集済み: John D'Errico 2014 年 12 月 28 日
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
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.
Zahid Iqbal Rana
Zahid Iqbal Rana 2014 年 12 月 23 日
TC is the total cost that's I need to compute, PL is the power Loss and Demand is the load demand. I need to compute TC for load demand + PL.

サインインしてコメントする。

回答 (1 件)

Sean de Wolski
Sean de Wolski 2014 年 12 月 17 日
  3 件のコメント
Zahid Iqbal Rana
Zahid Iqbal Rana 2014 年 12 月 23 日
Kindly tell me how to use this function for my code.
John D'Errico
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 ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by