How to modify a value in code.

1 view (last 30 days)
Zahid Iqbal Rana
Zahid Iqbal Rana on 17 Dec 2014
Edited: John D'Errico on 28 Dec 2014
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 Comments
Roger Stafford
Roger Stafford on 17 Dec 2014
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 on 23 Dec 2014
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.

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 17 Dec 2014
  3 Comments
Zahid Iqbal Rana
Zahid Iqbal Rana on 23 Dec 2014
Kindly tell me how to use this function for my code.
John D'Errico
John D'Errico on 28 Dec 2014
Edited: John D'Errico on 28 Dec 2014
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.

Sign in to comment.

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!