fminsearch for multi-input and single output

I have unknown function with two inputs ('x1' and 'x2') and one output ('Y') and a constant parameter 'p'. Each input is a vector of order [3000 x 3] and a output vector with order [3000 x 3]. Constant is [1 x 1]
best guess of unknown function is Y = (1-p)* 0.003* x1 + 275*p* x2.^4
i want to find a optimum value of parameter 'p' for which the error between the (Ymes - ) is minimum.
Ymes , X1 and X2 are known.
i tried fminsearch but it is not working
Ymes = rand(3000,3);
x1= rand(3000,3);
x2 = rand(3000,3);
fun = @(p) sum((Ymes - (1-p)*0.003* x1 + 275*p*x2.^4)).^2;
pguess = 1500;
[p,fminres] = fminsearch(fun,pguess)

Respuestas (1)

Torsten
Torsten el 28 de Feb. de 2018
Editada: Torsten el 28 de Feb. de 2018
Ymes = rand(3000,3);
x1= rand(3000,3);
x2 = rand(3000,3);
Ymes = Ymes();
x1 = x1();
x2 = x2();
fun = @(p) sum((Ymes - ((1-p)*0.003* x1 + 275*p*x2.^4)).^2);
%starting guess
pguess = [0.15];
%optimise
[p,fminres] = fminsearch(fun,pguess)
or simply:
Ymes = rand(3000,3);
x1= rand(3000,3);
x2 = rand(3000,3);
Ymes = Ymes();
x1 = x1();
x2 = x2();
p = (-0.003*x1+275*x2.^4)\(Ymes-0.003*x1)

7 comentarios

Adan91h
Adan91h el 28 de Feb. de 2018
Thankyou for your prompt answer.
Still the error is same.
Assignment has more non-singleton rhs dimensions than non-singleton subscripts Error in fminsearch (line 189) fv(:,1) = funfcn(x,varargin{:});
[p,fminres] = fminsearch(fun,pguess)
Did you see the change I made to your fun-definition ?
fun = @(p) sum((Ymes - ((1-p)*0.003* x1 + 275*p*x2.^4)).^2);
instead of
fun = @(p) sum((Ymes - (1-p)*0.003* x1 + 275*p*x2.^4)).^2;
with the following approach
Ymes = rand(3000,3);
x1= rand(3000,3);
x2 = rand(3000,3);
Ymes = Ymes();
x1 = x1();
x2 = x2();
p = (-0.003*x1+275*x2.^4)\(Ymes-0.003*x1)
p is 3x3 matrix.
P should be 1x1.
Adan91h
Adan91h el 28 de Feb. de 2018
Yes i noticed the change in the function definition.
but the error is in line
[p,fminres] = fminsearch(fun,pguess)
and it is the same error that i mentioned above.
In both cases, replace
Ymes = Ymes();
x1 = x1();
x2 = x2();
by
Ymes = Ymes(:);
x1 = x1(:);
x2 = x2(:);
Adan91h
Adan91h el 28 de Feb. de 2018
Thank you for your answer.
following commands changed the vectors from [3000 x 3] to [9000 x 1] Ymes = Ymes(:); x1 = x1(:); x2 = x2(:);
I can not do this thing in my case. because the entries of 2nd and 3rd columns are not independent.
I cannot assume that first columns of both inputs are only related to first column of output and so on.
I think fminsearch will not work for my case.
Do you know any other command?
Thanks in Advance!
My guess was that you want to fit
Ymes(i,j)
against
(1-p)*0.003* x1(i,j) + 275*p*x2(i,j).^4
for 1<=i<=3000 and 1<=j<=3.
This is what the code I suggested does.
If you want to do something else, you will have to clarify.
Best wishes
Torsten.

Iniciar sesión para comentar.

Preguntada:

el 28 de Feb. de 2018

Comentada:

el 1 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by