이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
using summation and modulus?
조회 수: 1 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148890/image.jpeg)
i think this is clearer
and that Fi(Pi) have to substituted here.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148892/image.jpeg)
답변 (1개)
Walter Roberson
2015년 9월 10일
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
Stephen23
2015년 9월 11일
편집: Stephen23
2015년 9월 11일
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
2015년 9월 11일
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
2015년 9월 11일
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.
JL555
2015년 9월 12일
no no F[i] & f[i] are two different variables. They are not functions. f[i](P[i,min] - P[i]) this is intended to be multiplied
Walter Roberson
2015년 9월 12일
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.
JL555
2015년 9월 12일
but im always getting an error with this equation.. error doesn't change if i use * or.* any suggestion?
Walter Roberson
2015년 9월 12일
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
2015년 9월 12일
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
2015년 9월 12일
You must have updated the source since that time. I will need the updated source.
JL555
2015년 9월 15일
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
2015년 9월 15일
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
2015년 9월 15일
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
2015년 9월 16일
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.
Walter Roberson
2015년 9월 17일
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 .*
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)