for i=1:n
for j=1:n
Pl=P(i)*B(i)(j)*P(j);
seems like i'm getting error with writing B(i)(j)...How will i code it in another way?

 Accepted Answer

Guillaume
Guillaume on 22 Sep 2015
Edited: Guillaume on 22 Sep 2015
Possibly, you meant to write
Pl(i,j) = P(i)*B(i,j)*P(j)
Or possibly, you meant something else entirely. It's impossible to tell with so little information.
In any case, you should go through the Getting Started tutorial.
Most likely also, the loops are not needed and it can all be done with matrix operations.

17 Comments

JL555
JL555 on 22 Sep 2015
Edited: JL555 on 22 Sep 2015
if pmin<Pi;
pmin=Pi;
pmin is a 1x6 matrix and Pi is 6x1 matrix...why am i still getting inner dimension must agree with <
You vectorized your code and you did not show us the new code. We can't tell you what needs to be fixed.
Pi=x(1:m,1:n1);
for i=1:n
for j=1:n
if pmin<Pi;
pmin=Pi;
else if Pi<pmax;
Pi=pmax;
C=Pi(i)*B(i,j)*Pi(j);
C1=B0(i)*Pi(i);
Pl=C+C1+Boo;
Pi=Pd+Pl;
end
end
end
end
That code will not generate the error message you indicate.
Note that you are doing a test of one vector compared to another. You would get a matrix dimensions must agree error there but not an inner dimensions must agree error.
If you were to switch so the two vectors are the same orientation then you face the problem that the test
if A < B
means the same as
if all(A < B)
and is only true if the comparison holds for every item in the vector.
JL555
JL555 on 22 Sep 2015
Actually the link to that answer is not valid anymore something terribly wrong with that program and i have a new one.And yes i'm getting a matrix dimension must agree ...so it is not possible to use the 'lt' to generate a matrix of 1x6 or should i compare with only one elemnt of that matrix?
if pmin(:) < Pi(:)
It is obvious to me from the code that you should be rewriting using matrix algebra. But every time I fix your code for you, you change it completely and look like you have not understood anything I wrote. You also do not answer questions about what size of output you are expecting from each step. It leaves me reluctant to assist.
JL555
JL555 on 22 Sep 2015
Edited: Walter Roberson on 22 Sep 2015
function [Ft Pi Pl]=FPAeld(x)
global objfun data pmin pmax Pd B B0 Boo
n=length(data(:,1));
[m n1]=size(x);
Pi=x(1:m,1:n1);
for i=1:n
for j=1:n
if data(1,4)<Pi;
data(1,4)=Pi;
else if Pi<data(1,5);
Pi=data(1,5);
C=Pi(i)*B(i,j)*Pi(j);
C1=B0(i)*Pi(i);
Pl=C+C1+Boo;
Pi=Pd+Pl;
end
end
end
end
a=data(:,1);
b=data(:,2);
c=data(:,3);
e=data(:,6);
f=data(:,7);
for i=1:n,
Pi=[Pi Pi(i)];
Ft=a(i)+b(i)*Pi(i)+c(i)*Pi(i).^2+abs(e(i)*sin(f(i)*(pmin-Pi(i))));
end
ok here the new code .....i'm feeding 'x' from an algorithm..its a 6x1 matrix. What i need in the end is Pi value which will have 6 values and i'll feed that value to the Ft formula in the end
Pi is a vector but if the if comparing it to data(1,4) holds then you assign data(1,4) to replace ALL of the vector.
JL555
JL555 on 22 Sep 2015
ok last question...'x' out there like i said is a 6x1 matrix..in the 5th line my Pi should be a 6x1 matrix too right? but i'm getting a single value ..why?
Why not just assign
Pi = x;
Since you use all of x?
JL555
JL555 on 22 Sep 2015
Yes all of x...But i did this instead Pi=[m n1]; still i,m getting one value..
JL555
JL555 on 22 Sep 2015
Oh and one thing ,i have the pseudo code of an algorithm ...any tutorials of how i can write that pseudo code into a matlab program..
I explained several days ago why
Pi=[Pi Pi(i)];
is going to just end up copying the same element over and over again. You are ignoring everything I write about why your program is not working.
JL555
JL555 on 22 Sep 2015
ok sorry dude i've been working with this program for one month now i managed to eliminate all the errors but everything is wrong with the programming...anyway are u familiar with economic load dispatch??
I am not familiar with economic load dispatch.
Note: I am not "dude". Or "man".
JL555
JL555 on 23 Sep 2015
Edited: JL555 on 23 Sep 2015
ok ..anyway thanks for your help really appreciate it.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 22 Sep 2015

Edited:

on 23 Sep 2015

Community Treasure Hunt

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

Start Hunting!