Hello,
Is it possible to use leastsq function on a 3D problem like z=f(x,y)?
if yes, can anyone share an example?
BR
My best guess so far
clc
clear
alvclose(winsid())
// Function definition
function F=funct(sol,X,Y)
F=1-exp(-(sol(1).*Y+sol(2)).*X.^2)+grand(size(Y,‘r’),size(Y,‘c’),“nor”,0,0.025)
// added noise
endfunction
// Function parameters
tmax=3
ao=4e-2
bo=1e-2
time=linspace(0,tmax,100)’
temp=linspace(20,80,4)’
[X,Y]=meshgrid(time,temp)
Z=funct([ao bo],X,Y)
// plot the noisy data
scatter3d(X,Y,Z,‘.’)
gca().zoom_box=[0 0 3 100 -0.2 1.2]
// Error definition
function dist = Error(sol, X, Y, Z)
dist = Z - funct(sol, X, Y);
endfunction
eps=10*%eps;
level=1000
p0 = [1 1]‘*1e-2;
[xopt, fopt, info] = leastsq(list(Error, X, Y, Z), p0’)//, [eps,eps,eps,level,eps,level]);