You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
using summation and modulus?
1 view (last 30 days)
Show older comments
i think this is clearer
and that Fi(Pi) have to substituted here.
Answers (1)
Walter Roberson
on 10 Sep 2015
I am having a difficult time reading that. It is a low quality image and my eyes are having trouble.
It looks to me as if it might read
F[i](P[G,i]) = a[i]*P[G,i]^2 + b[i]*P[G,i] + c[i] + abs( conjugate(e[i]) * sin( conjugate(f[i]) * (P[G,i min] - conjugate(P[G,i])) )
where I have represented subscript by [].
Please confirm that I have the operations right. For example, why did they use implicit mulitplication for a[i]*P[G,i]^2 but explicit multiplication inside the abs() ? And the conjugate bars are displaced from where I would expect them to be. What is "PG,i min" intended to mean?
22 Comments
Stephen23
on 11 Sep 2015
Edited: Stephen23
on 11 Sep 2015
They look like abs signs to me too. If they are modulo signs then it is a very non-standard way of showing it. In fact wikipedia lists thirteen mathematical uses of the vertical bar |, but modulo is not one of them.
If it is modulo, then where is the divisor/modulus specified?
Walter Roberson
on 11 Sep 2015
I used conjugate because the previous image had bars over some positions. The bars were positioned a bit oddly, such as being above subscripts, but conjugate was the only meaning I could think of for them.
modulus applied to real or complex number is another name for absolute value.
There are other meanings of modulus in other special forms of mathematics or physics, but they use different symbols.
Walter Roberson
on 11 Sep 2015
Your revised image appears to be
F[i](P[i]) = a[i] + b[i]*P[i] + c[i]*P[i]^2 + abs( e[i] * sin( f[i](P[i, min] - P[i])) )
except it is not clear whether the f[i](P[i,min] - P[i]) is intended to represent multiplication or a function call. If it is a function call then is the F[i] on the left side the same as the f[i] on the right side?
One way of expressing the above in MATLAB code would be
F_i = @(i) a(i) + b(i).*P(i) + c(i).*P(i).^2 + abs( e(i) .* sin( f(i)*(Pmin(i) - P(i))) );
This would take as input i, the index, and calculate a value. This assumes that the f[i] part is multiplication rather than function call. It also assumes that P(i) is a scalar, and that P[i,min] can be rewritten as a vector of values indexed by i.
Walter Roberson
on 12 Sep 2015
Then the anonymous function should be what you are looking for, provided that all of the subscripted quantities mentioned are intended to be scalars and that P subscript i,min is something you can calculate ahead of time and then index by i.
Walter Roberson
on 12 Sep 2015
a = rand(1,5);b = rand(1,5); c = rand(1,5); e = rand(1,5); f = rand(1,5); Pmin = rand(1,5) * 10; P = rand(1,5)*10;
F_i = @(i) a(i) + b(i).*P(i) + c(i).*P(i).^2 + abs( e(i) .* sin( f(i)*(Pmin(i) - P(i))) );
Fvalues = arrayfun(F_i, 1:length(a))
JL555
on 12 Sep 2015
This is the whole programming. The eqn can be found in the first script and the data in the second.Please take a look http://in.mathworks.com/matlabcentral/answers/241425-undefined-function-fun-for-input-argument-of-type-double
Walter Roberson
on 12 Sep 2015
You must have updated the source since that time. I will need the updated source.
Walter Roberson
on 15 Sep 2015
You can post it here.
JL555
on 15 Sep 2015
function [Ft,Pi,Pl]=FPAeld(x)
global objfun data pmin pmax DRi URi pi0 Pd B
n=length(data(:,1));
[m, n1]=size(x);
B11=B(1,1);
P=x(1:m,2:n);
B1n=B(1,2:n);
Bnn=B(2:n,2:n);
A=B11;
BB1=2*B1n*P';
B1=(BB1-1)';
C1=(P*Bnn*P');
C1=diag(C1);
Pl=Pd-(sum(P))'+C1;
x1=roots([A B1 Pl]);
% x=.5*(-B1-sqrt(B1^2-4*A*C))/A
Pi=abs(min(x1));
if Pi>data(1,5);
Pi=data(1,5);
else
end
if Pi<data(1,4);
Pi=data(1,4);
else
end
Pi=[Pi' P];
ai=data(:,1);
bi=data(:,2);
ci=data(:,3);
ei=data(:,6);
fi=data(:,7);
pmin=(data(:,4))';
for i=1:n
T(i)=ai.*Pi.^2+bi.*Pi+ci+abs(ei.*(fi.*(pmin-Pi)));
end
data
clear;
clc;
tic;
global objfun data pmax pmin B Pd pi0 URi DRi
objfun=@FPAeld;
data=[150 2 0.0016 50 200 50 0.063
25 2.5 0.01 20 80 40 0.098
0 1 0.0625 15 50 0 0
0 3.25 0.00834 10 35 0 0
0 3 0.025 10 30 0 0
0 3 0.025 12 40 0 0];
B=[0.0224 0.0103 0.0016 -0.0053 0.0009 -0.0013;0.0103 0.0158 0.0010 -0.0074 0.0007 0.0024;0.0016 0.0010 0.0474 -0.0687 -0.0060 -0.0350;-0.0053 -.0074 -.0687 .3464 0.0105 0.0534;0.0009 0.0007 -0.0060 0.0105 0.0119 .0007;-0.0013 0.0024 -0.0350 0.0534 0.0007 0.2353];
Pd=500;
pi0=[150;35;39;20;18;20];
URi=[60;28;10;10;10;15];
DRi=[80;10;20;05;05;06];
pmax=data(:,5);
pmin=data(:,4)
i'm getting dimension this error can u help please.
Error using .* Matrix dimensions must agree.
Error in FPAeld (line 34)
T(i)=ai.*Pi.^2+bi.*Pi+ci+abs(ei.*(fi.*(pmin-Pi)));
Walter Roberson
on 15 Sep 2015
What are you passing into objfun ?
Walter Roberson
on 15 Sep 2015
Your statement
Pi=[Pi' P];
is starting with Pi being a scalar (that is possibly complex.) P is an array which is something by 5, where the 5 is one fewer than the number of rows in data. [Pi' P] is horizontal concatenation. That concatenation is going to fail if P has two or more rows. Therefore the fact that you got further on to crash with the inner dimensions error shows that P must be a row vector, 1 by 5. P is extracted from x, the input argument, so the input argument must be a row vector. horizontal concatenation between a scalar and a row vector succeeds and will return a row vector. So in order to have gotten past this line, Pi would have to be a row vector.
In the statement
T(i)=ai.*Pi.^2+bi.*Pi+ci+abs(ei.*(fi.*(pmin-Pi)));
all the other items are either scalars or are column vectors. But Pi is a row vector. So pmin - Pi is a row vector, and fi .* that row vector is trying to use .* to multiply a column vector by a row vector. That is going to fail.
You seem to be expecting a scalar as the output from the expression, even though you are working with column vectors. That suggests to me that you do not want .* multiplication, that instead you want * multiplication, so that the column vector * a row vector gives you a scalar result. If that is what you want you need to be transposing both sides or else have the row vector on the left side of the *, such as
Pi.^2 * ai + Pi * bi + something
the "something" would have to be carefully considered to give a scalar output.
JL555
on 15 Sep 2015
function [Ft,Pi,Pl]=FPAeld(x)
global objfun data pmin pmax Pd B
n=length(data(:,1));
[m, n1]=size(x);
B11=B(1,1);
P=x(1:m,2:n);
B1n=B(1,2:n);
Bnn=B(2:n,2:n);
A=B11;
BB1=2*B1n*P';
B1=(BB1-1)';
C1=(P*Bnn*P');
C1=diag(C1);
Pl=Pd-(sum(P))'+C1;
x1=roots([A B1 Pl]);
% x=.5*(-B1-sqrt(B1^2-4*A*C))/A
Pi=abs(min(x1));
if Pi>data(1,5);
Pi=data(1,5);
else
end
if Pi<data(1,4);
Pi=data(1,4);
else
end
for i=1:n
Pi=[Pi Pi(i)];
Ft=data(i,1).*Pi(i).^2+data(i,2).*Pi(i)+data(i,3)+abs(data(i,6).*(data(i,7).*(data(i,4)-Pi)));
these are my changes
error: Attempted to access Pi(3); index out of bounds because numel(Pi)=1.
Walter Roberson
on 16 Sep 2015
Your Pi starts as a scalar. Your i starts as 1. The first thing you do inside the loop is Pi=[Pi Pi(i)]; which the first time through is going to be Pi=[Pi Pi(1)] which is going to extend Pi with a copy of the first element. Then the next iteration of i you again have Pi=[Pi Pi(i)] which is going to be Pi=[Pi Pi(2)] and we already know that Pi(2) is a copy of the original Pi(1) so your Pi is now going to be three elements long, all copies of the same value. Are you sure you want to do that?
Your second line of the loop has
Ft = data(i,1).*Pi(i).^2+data(i,2).*Pi(i)+data(i,3) + abs(data(i,6).*(data(i,7).*(data(i,4)-Pi)));
which indexes Pi(i) in each location except the last one. Your Pi is growing, so each iteration the result of Ft is going to be one value longer.
And then your code supposedly ends without an "end" statement. I would judge that the error message you are encountering is on some code after what you posted here.
You should always post the complete error message with traceback, so that we do not need to guess about where the problem is.
JL555
on 17 Sep 2015
Edited: JL555
on 17 Sep 2015
thanks for responding..anyway "end" is not the error and yes the last one should be Pi(i). but i'm getting this error
Attempted to access P(1); index out of bounds because numel(P)=0.
Error in FPAeld (line 28)
Pi=[Pi P(i)];
Walter Roberson
on 17 Sep 2015
Change the lines
ai=data(:,1);
bi=data(:,2);
ci=data(:,3);
ei=data(:,6);
fi=data(:,7);
to
ai = data(:,1) .';
bi = data(:,2) .';
ci = data(:,3) .';
ei = data(:,6) .';
fi = data(:,7) .';
then they will all agree in size, 1 x 6, with your 1 x 6 Pi, and you will not get the error about matrix dimensions not agreeing for .*
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)