Hello, I am using Fminsearch to find 4 unknowns and i run into the error, "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" and Number of array dimensions must match for binary array op. code and function are below.

1 vue (au cours des 30 derniers jours)
AA=936077.2132;
BB=150274.5692;
CC = 11575.20685;
DD = 7915.610549;
format long g
%%A grid of x1 x2 x3 x4 is created which will be used to run through the gaussian code.
x1min = 0; x1max = 500;
x2min = 0; x2max = 500;
x3min = 0; x3max = 500;
x4min = 0; x4max = 500;
[x1, x2, x3 ,x4] = ndgrid( linspace(x1min, x1max, 10), linspace(x2min, x2max, 10),linspace(x3min, x3max, 10),linspace(x4min, x4max, 10));
fx1 = @(x)fx2(F, x(1), x(2), x(3),x(4), A, B, C, D, AA, BB, CC, DD); %%we assign the already saved function fxp to fx1
[xvals,fvals] = fminsearch(fx1, 50*rand(1,4), struct('MaxFunEvals', 20000000000,'MaxIter',1e12,'Tolx',1.0e-25))

Réponses (1)

Ameer Hamza
Ameer Hamza le 20 Juin 2020
fminsearch() requires that the objective function return a scalar value, however, in this case, fx1 return a 10x10x10x10 array. You need to convert it into a scalar function. For example
fx1 = @(x) sum(fx2(F, x(1), x(2), x(3),x(4), A, B, C, D, AA, BB, CC, DD), 'all');

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by