How to modify a value in code.

1 次查看(过去 30 天)
Zahid Iqbal Rana
Zahid Iqbal Rana 2014-12-17
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 CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by