Quantcast

minimization problem, sqp

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

minimization problem, sqp

Hackstein
Dear list,

I am relatively new to octave and dealing with the following minimization problem:
Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex numbers. My goal is to determine the real numbers x(1), x(2), x(3), x(4),x(5),x(6),x(7) with -1<=x(j)<=1, j=1,..,7, such that the function
 (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
takes its minimal value.

I made the following attempt using sqp:

function erg=fun(x)
erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
endfunction

function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
global b;
minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
endfunction

Thanks a lot in advance!

Sincerely yours,

Urs Hackstein

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Juan Pablo Carbajal-2
On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
<[hidden email]> wrote:

> Dear list,
>
> I am relatively new to octave and dealing with the following minimization
> problem:
> Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex numbers. My
> goal is to determine the real numbers x(1), x(2), x(3), x(4),x(5),x(6),x(7)
> with -1<=x(j)<=1, j=1,..,7, such that the function
>
> (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
> takes its minimal value.
>
> I made the following attempt using sqp:
>
> function erg=fun(x)
> erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
> endfunction
>
> function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
> global b;
> minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
> endfunction
>
> Thanks a lot in advance!
>
> Sincerely yours,
>
> Urs Hackstein
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

 Hi Urs,

Great! and what is the problem?
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Fwd: minimization problem, sqp

Hackstein


---------- Forwarded message ----------
From: Urs Hackstein <[hidden email]>
Date: 2013/2/25
Subject: Re: minimization problem, sqp
To: Juan Pablo Carbajal <[hidden email]>


Hi Juan,

the problem is that my attempt does not work and I am not familiar enough with the sqp syntax to get the x(1),...,x(7) as output. Thus any suggestions for a correct program?

Sincerely yours,

Urs Hackstein

2013/2/25 Juan Pablo Carbajal <[hidden email]>
On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
<[hidden email]> wrote:
> Dear list,
>
> I am relatively new to octave and dealing with the following minimization
> problem:
> Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex numbers. My
> goal is to determine the real numbers x(1), x(2), x(3), x(4),x(5),x(6),x(7)
> with -1<=x(j)<=1, j=1,..,7, such that the function
>
> (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
> takes its minimal value.
>
> I made the following attempt using sqp:
>
> function erg=fun(x)
> erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
> endfunction
>
> function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
> global b;
> minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
> endfunction
>
> Thanks a lot in advance!
>
> Sincerely yours,
>
> Urs Hackstein
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

 Hi Urs,

Great! and what is the problem?



_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Juan Pablo Carbajal-2
On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
<[hidden email]> wrote:

>
>
> ---------- Forwarded message ----------
> From: Urs Hackstein <[hidden email]>
> Date: 2013/2/25
> Subject: Re: minimization problem, sqp
> To: Juan Pablo Carbajal <[hidden email]>
>
>
> Hi Juan,
>
> the problem is that my attempt does not work and I am not familiar enough
> with the sqp syntax to get the x(1),...,x(7) as output. Thus any suggestions
> for a correct program?
>
>
> Sincerely yours,
>
> Urs Hackstein
>
> 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>>
>> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> > Dear list,
>> >
>> > I am relatively new to octave and dealing with the following
>> > minimization
>> > problem:
>> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex numbers.
>> > My
>> > goal is to determine the real numbers x(1), x(2), x(3),
>> > x(4),x(5),x(6),x(7)
>> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >
>> >
>> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> > takes its minimal value.
>> >
>> > I made the following attempt using sqp:
>> >
>> > function erg=fun(x)
>> >
>> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> > endfunction
>> >
>> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> > global b;
>> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> > endfunction
>> >
>> > Thanks a lot in advance!
>> >
>> > Sincerely yours,
>> >
>> > Urs Hackstein
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > [hidden email]
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >
>>
>>  Hi Urs,
>>
>> Great! and what is the problem?
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Urs,

Ok, have you try reading the help of sqp?
> help sqp

If you have questions after reading that we can help you, but do
please read the manual. also search the web, there are plenty of
examples using sqp
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Hackstein
Juan,

I read the manual before posting my question (my attempt was the result of reading it) and I did it again, but it didn't help. I still get the error "`b' undefined near line 3 column 6" and don't know how to fix it. Perhaps the problem is that fun is not just a function of x, but also of b and the psj, but, as I said, I don't know how to fix it.


2013/2/25 Juan Pablo Carbajal <[hidden email]>
On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
<[hidden email]> wrote:
>
>
> ---------- Forwarded message ----------
> From: Urs Hackstein <[hidden email]>
> Date: 2013/2/25
> Subject: Re: minimization problem, sqp
> To: Juan Pablo Carbajal <[hidden email]>
>
>
> Hi Juan,
>
> the problem is that my attempt does not work and I am not familiar enough
> with the sqp syntax to get the x(1),...,x(7) as output. Thus any suggestions
> for a correct program?
>
>
> Sincerely yours,
>
> Urs Hackstein
>
> 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>>
>> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> > Dear list,
>> >
>> > I am relatively new to octave and dealing with the following
>> > minimization
>> > problem:
>> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex numbers.
>> > My
>> > goal is to determine the real numbers x(1), x(2), x(3),
>> > x(4),x(5),x(6),x(7)
>> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >
>> >
>> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> > takes its minimal value.
>> >
>> > I made the following attempt using sqp:
>> >
>> > function erg=fun(x)
>> >
>> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> > endfunction
>> >
>> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> > global b;
>> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> > endfunction
>> >
>> > Thanks a lot in advance!
>> >
>> > Sincerely yours,
>> >
>> > Urs Hackstein
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > [hidden email]
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >
>>
>>  Hi Urs,
>>
>> Great! and what is the problem?
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Urs,

Ok, have you try reading the help of sqp?
> help sqp

If you have questions after reading that we can help you, but do
please read the manual. also search the web, there are plenty of
examples using sqp


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Juan Pablo Carbajal-2
On Mon, Feb 25, 2013 at 4:37 PM, Urs Hackstein
<[hidden email]> wrote:

> Juan,
>
> I read the manual before posting my question (my attempt was the result of
> reading it) and I did it again, but it didn't help. I still get the error
> "`b' undefined near line 3 column 6" and don't know how to fix it. Perhaps
> the problem is that fun is not just a function of x, but also of b and the
> psj, but, as I said, I don't know how to fix it.
>
>
> 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>>
>> On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> >
>> >
>> > ---------- Forwarded message ----------
>> > From: Urs Hackstein <[hidden email]>
>> > Date: 2013/2/25
>> > Subject: Re: minimization problem, sqp
>> > To: Juan Pablo Carbajal <[hidden email]>
>> >
>> >
>> > Hi Juan,
>> >
>> > the problem is that my attempt does not work and I am not familiar
>> > enough
>> > with the sqp syntax to get the x(1),...,x(7) as output. Thus any
>> > suggestions
>> > for a correct program?
>> >
>> >
>> > Sincerely yours,
>> >
>> > Urs Hackstein
>> >
>> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >>
>> >> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> >> <[hidden email]> wrote:
>> >> > Dear list,
>> >> >
>> >> > I am relatively new to octave and dealing with the following
>> >> > minimization
>> >> > problem:
>> >> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex
>> >> > numbers.
>> >> > My
>> >> > goal is to determine the real numbers x(1), x(2), x(3),
>> >> > x(4),x(5),x(6),x(7)
>> >> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >> >
>> >> >
>> >> >
>> >> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> > takes its minimal value.
>> >> >
>> >> > I made the following attempt using sqp:
>> >> >
>> >> > function erg=fun(x)
>> >> >
>> >> >
>> >> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> > endfunction
>> >> >
>> >> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> >> > global b;
>> >> >
>> >> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> >> > endfunction
>> >> >
>> >> > Thanks a lot in advance!
>> >> >
>> >> > Sincerely yours,
>> >> >
>> >> > Urs Hackstein
>> >> >
>> >> > _______________________________________________
>> >> > Help-octave mailing list
>> >> > [hidden email]
>> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >
>> >>
>> >>  Hi Urs,
>> >>
>> >> Great! and what is the problem?
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > [hidden email]
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >
>>
>> Urs,
>>
>> Ok, have you try reading the help of sqp?
>> > help sqp
>>
>> If you have questions after reading that we can help you, but do
>> please read the manual. also search the web, there are plenty of
>> examples using sqp
>
>

Hi Urs,

Yes, that may be a problem. Lets say you want of din the minimum of the function

f(x; a, b) = x*(a*x + b)

The function is parametrized by a and b, i.e. it represents a family
of functions. To optimize you have to specify which one you want to
work with.
So we create the parametrized function

function y = f (x, p)
  y = x .* (p(1)*x + p(2));
endfunction

Before we can pass it to sqp we have to define the values of the
parameters, one way of doing that is using a wrapper (I think is the
recommended way, though it may be less efficient than other ways, but
do not know for how much)

a = 1; b = -1;
fwrap = @(x) f (x,[a,b])

Then we can call sqp

 sqp (2*rand(1)-1, fwrap)

and I get

ans =  0.50000

as expected.

Hope this solves your problem
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Hackstein
Hi Juan,

thanks a lot for your explanations. If I understand you correctly, my script should be the following:

function erg=funp(x,p)
erg=(p(1)-x(1).*p(2)-x(2).*p(3)-x(3).*p(4)-x(4).*p(5)-x(5).*p(6)-x(6).*p(7)-x(7).*p(8)).^2
endfunction

function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
global b;
global ps1;
global ps2;
global ps3;
global ps4;
global ps5;
global ps6;
global ps7;
a1=b; a2=ps1; a3=ps2; a4=ps3; a5=ps4; a6=ps5; a7=ps6; a8=ps7;
funpwrap=@(x)funp(x,[a1,a2,a3,a4,a5,a6,a7,a8])
minimi=sqp([0;0;0;0;0;0;0],funpwrap,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
endfunction

But if  I call minimize(2,1,0,0,0,0,0,0), I receive the following error:
funpwrap =

@(x) funp (x, [a1, a2, a3, a4, a5, a6, a7, a8])

error: A(I): Index exceeds matrix dimension.
error: called from:
error:   /home/hackstein/Dominantepole/funp.m at line 2, column 4
error:    at line -1, column -1
error:   /usr/share/octave/3.2.4/m/optimization/sqp.m at line 347, column 9
error:   /home/hackstein/Dominantepole/minimize.m at line 12, column 7

How can we get rid of this error?


2013/2/28 Juan Pablo Carbajal <[hidden email]>
On Mon, Feb 25, 2013 at 4:37 PM, Urs Hackstein
<[hidden email]> wrote:
> Juan,
>
> I read the manual before posting my question (my attempt was the result of
> reading it) and I did it again, but it didn't help. I still get the error
> "`b' undefined near line 3 column 6" and don't know how to fix it. Perhaps
> the problem is that fun is not just a function of x, but also of b and the
> psj, but, as I said, I don't know how to fix it.
>
>
> 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>>
>> On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> >
>> >
>> > ---------- Forwarded message ----------
>> > From: Urs Hackstein <[hidden email]>
>> > Date: 2013/2/25
>> > Subject: Re: minimization problem, sqp
>> > To: Juan Pablo Carbajal <[hidden email]>
>> >
>> >
>> > Hi Juan,
>> >
>> > the problem is that my attempt does not work and I am not familiar
>> > enough
>> > with the sqp syntax to get the x(1),...,x(7) as output. Thus any
>> > suggestions
>> > for a correct program?
>> >
>> >
>> > Sincerely yours,
>> >
>> > Urs Hackstein
>> >
>> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >>
>> >> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> >> <[hidden email]> wrote:
>> >> > Dear list,
>> >> >
>> >> > I am relatively new to octave and dealing with the following
>> >> > minimization
>> >> > problem:
>> >> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex
>> >> > numbers.
>> >> > My
>> >> > goal is to determine the real numbers x(1), x(2), x(3),
>> >> > x(4),x(5),x(6),x(7)
>> >> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >> >
>> >> >
>> >> >
>> >> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> > takes its minimal value.
>> >> >
>> >> > I made the following attempt using sqp:
>> >> >
>> >> > function erg=fun(x)
>> >> >
>> >> >
>> >> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> > endfunction
>> >> >
>> >> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> >> > global b;
>> >> >
>> >> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> >> > endfunction
>> >> >
>> >> > Thanks a lot in advance!
>> >> >
>> >> > Sincerely yours,
>> >> >
>> >> > Urs Hackstein
>> >> >
>> >> > _______________________________________________
>> >> > Help-octave mailing list
>> >> > [hidden email]
>> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >
>> >>
>> >>  Hi Urs,
>> >>
>> >> Great! and what is the problem?
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > [hidden email]
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >
>>
>> Urs,
>>
>> Ok, have you try reading the help of sqp?
>> > help sqp
>>
>> If you have questions after reading that we can help you, but do
>> please read the manual. also search the web, there are plenty of
>> examples using sqp
>
>

Hi Urs,

Yes, that may be a problem. Lets say you want of din the minimum of the function

f(x; a, b) = x*(a*x + b)

The function is parametrized by a and b, i.e. it represents a family
of functions. To optimize you have to specify which one you want to
work with.
So we create the parametrized function

function y = f (x, p)
  y = x .* (p(1)*x + p(2));
endfunction

Before we can pass it to sqp we have to define the values of the
parameters, one way of doing that is using a wrapper (I think is the
recommended way, though it may be less efficient than other ways, but
do not know for how much)

a = 1; b = -1;
fwrap = @(x) f (x,[a,b])

Then we can call sqp

 sqp (2*rand(1)-1, fwrap)

and I get

ans =  0.50000

as expected.

Hope this solves your problem


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Juan Pablo Carbajal-2
On Thu, Feb 28, 2013 at 2:24 PM, Urs Hackstein
<[hidden email]> wrote:

> Hi Juan,
>
> thanks a lot for your explanations. If I understand you correctly, my script
> should be the following:
>
> function erg=funp(x,p)
> erg=(p(1)-x(1).*p(2)-x(2).*p(3)-x(3).*p(4)-x(4).*p(5)-x(5).*p(6)-x(6).*p(7)-x(7).*p(8)).^2
> endfunction
>
> function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
> global b;
> global ps1;
> global ps2;
> global ps3;
> global ps4;
> global ps5;
> global ps6;
> global ps7;
> a1=b; a2=ps1; a3=ps2; a4=ps3; a5=ps4; a6=ps5; a7=ps6; a8=ps7;
> funpwrap=@(x)funp(x,[a1,a2,a3,a4,a5,a6,a7,a8])
> minimi=sqp([0;0;0;0;0;0;0],funpwrap,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
> endfunction
>
> But if  I call minimize(2,1,0,0,0,0,0,0), I receive the following error:
> funpwrap =
>
> @(x) funp (x, [a1, a2, a3, a4, a5, a6, a7, a8])
>
> error: A(I): Index exceeds matrix dimension.
> error: called from:
> error:   /home/hackstein/Dominantepole/funp.m at line 2, column 4
> error:    at line -1, column -1
> error:   /usr/share/octave/3.2.4/m/optimization/sqp.m at line 347, column 9
> error:   /home/hackstein/Dominantepole/minimize.m at line 12, column 7
>
> How can we get rid of this error?
>
>
> 2013/2/28 Juan Pablo Carbajal <[hidden email]>
>>
>> On Mon, Feb 25, 2013 at 4:37 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> > Juan,
>> >
>> > I read the manual before posting my question (my attempt was the result
>> > of
>> > reading it) and I did it again, but it didn't help. I still get the
>> > error
>> > "`b' undefined near line 3 column 6" and don't know how to fix it.
>> > Perhaps
>> > the problem is that fun is not just a function of x, but also of b and
>> > the
>> > psj, but, as I said, I don't know how to fix it.
>> >
>> >
>> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >>
>> >> On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
>> >> <[hidden email]> wrote:
>> >> >
>> >> >
>> >> > ---------- Forwarded message ----------
>> >> > From: Urs Hackstein <[hidden email]>
>> >> > Date: 2013/2/25
>> >> > Subject: Re: minimization problem, sqp
>> >> > To: Juan Pablo Carbajal <[hidden email]>
>> >> >
>> >> >
>> >> > Hi Juan,
>> >> >
>> >> > the problem is that my attempt does not work and I am not familiar
>> >> > enough
>> >> > with the sqp syntax to get the x(1),...,x(7) as output. Thus any
>> >> > suggestions
>> >> > for a correct program?
>> >> >
>> >> >
>> >> > Sincerely yours,
>> >> >
>> >> > Urs Hackstein
>> >> >
>> >> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >> >>
>> >> >> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> >> >> <[hidden email]> wrote:
>> >> >> > Dear list,
>> >> >> >
>> >> >> > I am relatively new to octave and dealing with the following
>> >> >> > minimization
>> >> >> > problem:
>> >> >> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex
>> >> >> > numbers.
>> >> >> > My
>> >> >> > goal is to determine the real numbers x(1), x(2), x(3),
>> >> >> > x(4),x(5),x(6),x(7)
>> >> >> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> >> > takes its minimal value.
>> >> >> >
>> >> >> > I made the following attempt using sqp:
>> >> >> >
>> >> >> > function erg=fun(x)
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> >> > endfunction
>> >> >> >
>> >> >> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> >> >> > global b;
>> >> >> >
>> >> >> >
>> >> >> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> >> >> > endfunction
>> >> >> >
>> >> >> > Thanks a lot in advance!
>> >> >> >
>> >> >> > Sincerely yours,
>> >> >> >
>> >> >> > Urs Hackstein
>> >> >> >
>> >> >> > _______________________________________________
>> >> >> > Help-octave mailing list
>> >> >> > [hidden email]
>> >> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >> >
>> >> >>
>> >> >>  Hi Urs,
>> >> >>
>> >> >> Great! and what is the problem?
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > Help-octave mailing list
>> >> > [hidden email]
>> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >
>> >>
>> >> Urs,
>> >>
>> >> Ok, have you try reading the help of sqp?
>> >> > help sqp
>> >>
>> >> If you have questions after reading that we can help you, but do
>> >> please read the manual. also search the web, there are plenty of
>> >> examples using sqp
>> >
>> >
>>
>> Hi Urs,
>>
>> Yes, that may be a problem. Lets say you want of din the minimum of the
>> function
>>
>> f(x; a, b) = x*(a*x + b)
>>
>> The function is parametrized by a and b, i.e. it represents a family
>> of functions. To optimize you have to specify which one you want to
>> work with.
>> So we create the parametrized function
>>
>> function y = f (x, p)
>>   y = x .* (p(1)*x + p(2));
>> endfunction
>>
>> Before we can pass it to sqp we have to define the values of the
>> parameters, one way of doing that is using a wrapper (I think is the
>> recommended way, though it may be less efficient than other ways, but
>> do not know for how much)
>>
>> a = 1; b = -1;
>> fwrap = @(x) f (x,[a,b])
>>
>> Then we can call sqp
>>
>>  sqp (2*rand(1)-1, fwrap)
>>
>> and I get
>>
>> ans =  0.50000
>>
>> as expected.
>>
>> Hope this solves your problem
>
>

First, If you use the me wrapper method you do not need the global
variables nor the minimize function.

function erg = funp(x,p)
  erg = ( p(1) - p(2:end) * x(:) ).^2
endfunction

funpwrap = @(x)funp(x,[b,ps1,ps2,ps3,ps4,ps5,ps6,ps7])
x0  = zeros (7,1);
lbound = -1;
ubound = 1;
sqp (x0, funpwrap,[],[],lbound,ubound)

Now, read the help of sqp again more carefully, I think you haven't
payed enough attention.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: minimization problem, sqp

Juan Pablo Carbajal-2
On Tue, Mar 5, 2013 at 6:04 PM, Urs Hackstein
<[hidden email]> wrote:

>
>
> 2013/2/28 Juan Pablo Carbajal <[hidden email]>
>>
>> On Thu, Feb 28, 2013 at 2:24 PM, Urs Hackstein
>> <[hidden email]> wrote:
>> > Hi Juan,
>> >
>> > thanks a lot for your explanations. If I understand you correctly, my
>> > script
>> > should be the following:
>> >
>> > function erg=funp(x,p)
>> >
>> > erg=(p(1)-x(1).*p(2)-x(2).*p(3)-x(3).*p(4)-x(4).*p(5)-x(5).*p(6)-x(6).*p(7)-x(7).*p(8)).^2
>> > endfunction
>> >
>> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> > global b;
>> > global ps1;
>> > global ps2;
>> > global ps3;
>> > global ps4;
>> > global ps5;
>> > global ps6;
>> > global ps7;
>> > a1=b; a2=ps1; a3=ps2; a4=ps3; a5=ps4; a6=ps5; a7=ps6; a8=ps7;
>> > funpwrap=@(x)funp(x,[a1,a2,a3,a4,a5,a6,a7,a8])
>> >
>> > minimi=sqp([0;0;0;0;0;0;0],funpwrap,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> > endfunction
>> >
>> > But if  I call minimize(2,1,0,0,0,0,0,0), I receive the following error:
>> > funpwrap =
>> >
>> > @(x) funp (x, [a1, a2, a3, a4, a5, a6, a7, a8])
>> >
>> > error: A(I): Index exceeds matrix dimension.
>> > error: called from:
>> > error:   /home/hackstein/Dominantepole/funp.m at line 2, column 4
>> > error:    at line -1, column -1
>> > error:   /usr/share/octave/3.2.4/m/optimization/sqp.m at line 347,
>> > column 9
>> > error:   /home/hackstein/Dominantepole/minimize.m at line 12, column 7
>> >
>> > How can we get rid of this error?
>> >
>> >
>> > 2013/2/28 Juan Pablo Carbajal <[hidden email]>
>> >>
>> >> On Mon, Feb 25, 2013 at 4:37 PM, Urs Hackstein
>> >> <[hidden email]> wrote:
>> >> > Juan,
>> >> >
>> >> > I read the manual before posting my question (my attempt was the
>> >> > result
>> >> > of
>> >> > reading it) and I did it again, but it didn't help. I still get the
>> >> > error
>> >> > "`b' undefined near line 3 column 6" and don't know how to fix it.
>> >> > Perhaps
>> >> > the problem is that fun is not just a function of x, but also of b
>> >> > and
>> >> > the
>> >> > psj, but, as I said, I don't know how to fix it.
>> >> >
>> >> >
>> >> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >> >>
>> >> >> On Mon, Feb 25, 2013 at 3:32 PM, Urs Hackstein
>> >> >> <[hidden email]> wrote:
>> >> >> >
>> >> >> >
>> >> >> > ---------- Forwarded message ----------
>> >> >> > From: Urs Hackstein <[hidden email]>
>> >> >> > Date: 2013/2/25
>> >> >> > Subject: Re: minimization problem, sqp
>> >> >> > To: Juan Pablo Carbajal <[hidden email]>
>> >> >> >
>> >> >> >
>> >> >> > Hi Juan,
>> >> >> >
>> >> >> > the problem is that my attempt does not work and I am not familiar
>> >> >> > enough
>> >> >> > with the sqp syntax to get the x(1),...,x(7) as output. Thus any
>> >> >> > suggestions
>> >> >> > for a correct program?
>> >> >> >
>> >> >> >
>> >> >> > Sincerely yours,
>> >> >> >
>> >> >> > Urs Hackstein
>> >> >> >
>> >> >> > 2013/2/25 Juan Pablo Carbajal <[hidden email]>
>> >> >> >>
>> >> >> >> On Mon, Feb 25, 2013 at 2:30 PM, Urs Hackstein
>> >> >> >> <[hidden email]> wrote:
>> >> >> >> > Dear list,
>> >> >> >> >
>> >> >> >> > I am relatively new to octave and dealing with the following
>> >> >> >> > minimization
>> >> >> >> > problem:
>> >> >> >> > Let b, ps1, ps2, ps3, ps4, ps5, ps6 and ps7 arbitrary complex
>> >> >> >> > numbers.
>> >> >> >> > My
>> >> >> >> > goal is to determine the real numbers x(1), x(2), x(3),
>> >> >> >> > x(4),x(5),x(6),x(7)
>> >> >> >> > with -1<=x(j)<=1, j=1,..,7, such that the function
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > (b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> >> >> > takes its minimal value.
>> >> >> >> >
>> >> >> >> > I made the following attempt using sqp:
>> >> >> >> >
>> >> >> >> > function erg=fun(x)
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > erg=(b-x(1).*ps1-x(2).*ps2-x(3).*ps3-x(4).*ps4-x(5).*ps5-x(6).*ps6-x(7).*ps7).^2
>> >> >> >> > endfunction
>> >> >> >> >
>> >> >> >> > function minimi=minimize(b,ps1,ps2,ps3,ps4,ps5,ps6,ps7)
>> >> >> >> > global b;
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > minimi=sqp([0;0;0;0;0;0;0],@fun,[-1;-1;-1;-1;-1;-1;-1],[1;1;1;1;1;1;1])
>> >> >> >> > endfunction
>> >> >> >> >
>> >> >> >> > Thanks a lot in advance!
>> >> >> >> >
>> >> >> >> > Sincerely yours,
>> >> >> >> >
>> >> >> >> > Urs Hackstein
>> >> >> >> >
>> >> >> >> > _______________________________________________
>> >> >> >> > Help-octave mailing list
>> >> >> >> > [hidden email]
>> >> >> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >> >> >
>> >> >> >>
>> >> >> >>  Hi Urs,
>> >> >> >>
>> >> >> >> Great! and what is the problem?
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > _______________________________________________
>> >> >> > Help-octave mailing list
>> >> >> > [hidden email]
>> >> >> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >> >> >
>> >> >>
>> >> >> Urs,
>> >> >>
>> >> >> Ok, have you try reading the help of sqp?
>> >> >> > help sqp
>> >> >>
>> >> >> If you have questions after reading that we can help you, but do
>> >> >> please read the manual. also search the web, there are plenty of
>> >> >> examples using sqp
>> >> >
>> >> >
>> >>
>> >> Hi Urs,
>> >>
>> >> Yes, that may be a problem. Lets say you want of din the minimum of the
>> >> function
>> >>
>> >> f(x; a, b) = x*(a*x + b)
>> >>
>> >> The function is parametrized by a and b, i.e. it represents a family
>> >> of functions. To optimize you have to specify which one you want to
>> >> work with.
>> >> So we create the parametrized function
>> >>
>> >> function y = f (x, p)
>> >>   y = x .* (p(1)*x + p(2));
>> >> endfunction
>> >>
>> >> Before we can pass it to sqp we have to define the values of the
>> >> parameters, one way of doing that is using a wrapper (I think is the
>> >> recommended way, though it may be less efficient than other ways, but
>> >> do not know for how much)
>> >>
>> >> a = 1; b = -1;
>> >> fwrap = @(x) f (x,[a,b])
>> >>
>> >> Then we can call sqp
>> >>
>> >>  sqp (2*rand(1)-1, fwrap)
>> >>
>> >> and I get
>> >>
>> >> ans =  0.50000
>> >>
>> >> as expected.
>> >>
>> >> Hope this solves your problem
>> >
>> >
>>
>> First, If you use the me wrapper method you do not need the global
>> variables nor the minimize function.
>>
>> function erg = funp(x,p)
>>   erg = ( p(1) - p(2:end) * x(:) ).^2
>> endfunction
>>
>> funpwrap = @(x)funp(x,[b,ps1,ps2,ps3,ps4,ps5,ps6,ps7])
>> x0  = zeros (7,1);
>> lbound = -1;
>> ubound = 1;
>> sqp (x0, funpwrap,[],[],lbound,ubound)
>>
>> Now, read the help of sqp again more carefully, I think you haven't
>> payed enough attention.
>
> Hi Juan,
>
> thanks a lot for the code. I need the minimize function because I want to
> call this function as a subfunction of another function. But apparently I
> still overlook something: As I call the function
> minimize(1+i,2+i,3+i,4+i,0,0,0,0), I receive the following error:
> funpwrap =
>
> @(x) funp (x, [b, ps1, ps2, ps3, ps4, ps5, ps6, ps7])
>
> erg =  0 + 2i
> erg =  0 + 2i
> erg = -2.9802e-08 + 2.0000e+00i
> erg = -5.9605e-08 + 2.0000e+00i
> erg = -8.9407e-08 + 2.0000e+00i
> erg =  0 + 2i
> erg =  0 + 2i
> erg =  0 + 2i
> erg =  0 + 2i
> error: octave_base_value::array_value(): wrong type argument `complex
> matrix'
> error: octave_base_value::int_value (): wrong type argument `scalar'
> error: __qp__: invalid arguments
> error: called from:
> error:   /usr/share/octave/3.2.4/m/optimization/qp.m at line 317, column 32
> error:   /usr/share/octave/3.2.4/m/optimization/sqp.m at line 414, column 34
> error:   /home/hackstein/Dominantepole/minimize.m at line 7, column 5
>
> Could you give me a hint?

Hi Urs,

Keep the mailing list always in CC.

I think qp doesn't accept complex inputs (can't you work with real and
imag part separatelly?). The error lines that you should have noted
are
error: octave_base_value::array_value(): wrong type argument `complex matrix'
error: octave_base_value::int_value (): wrong type argument `scalar'
error: __qp__: invalid arguments
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Loading...