How to modify a value in code.

1 visualización (últimos 30 días)
Zahid Iqbal Rana
Zahid Iqbal Rana el 17 de Dic. de 2014
Editada: John D'Errico el 28 de Dic. de 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 comentarios
Roger Stafford
Roger Stafford el 17 de Dic. de 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 el 23 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by