As far as I have tested it, it does not work. First, errors in line 405 (the name and the comma instead the :) make the program useless. Anyway the code is good to understand Famos data structure. Starting from that, I will try to do some efforts myselff to develop a code to import data.

18 Mar 2010

txt2mat
fast and versatile ascii data import capable of handling large text files
Author: Andres

Thank you for this. I use it in imgraft.glaciology.net for optimising camera parameters and it works great. I have also used it in another project where it also delivered a massive performance boost.

Sorry, I repair a wrong copying.
The right solutions are
x =
-0.0000
1.0000
ssq =
2.6880e-009
cnt =
149
===================
x =
0.0000
1.0000
ssq =
1.2586e-021
cnt =
4
===================
x =
0.0000
1.0000
ssq =
1.2586e-021
cnt =
4
Miroslav

Dear Amin
I thank you for your interest in my function LMFnlsq. The difference in solutions between LMFnlsq and fminsearch is caused by default preset tolerances 'XTol' and FunTol'.By changing them, you would obtain just the same result. It is obvious from the first group of results from the script Amin.m with improved required tolerances:
% Amin.m
%%%%%%%%% 2014-01-03
clc
clear all
close all
format compact
y =@(x) x^2+1;
c =@(x) complex(x(1),x(2));
fx=@(x) abs(y(c(x)));
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5],'XTol',1e-10,'FunTol',1e-10)
fprintf('===================\n');
% solution of 2 equations: Re c^2 + 1; Im c^2 = 0;
fx=@(x) [real(y(c(x))); imag(y(c(x)))];
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5])
fprintf('===================\n');
% solution of 2 equations: Re c^2 + 1; Im c^2 = 0;
c = @(x) complex(x(1),x(2))^2;
fx = @(x) [real(c(x))+1; imag(c(x))];
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5])
Solutions of all cases are:
% Amin.m
%%%%%%%%% 2014-01-03
clc
clear all
close all
format compact
y =@(x) x^2+1;
c =@(x) complex(x(1),x(2));
fx=@(x) abs(y(c(x)));
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5],'XTol',1e-10,'FunTol',1e-10)
fprintf('===================\n');
% solution of 2 equations: Re f + 1; Im c^2 = 0;
fx=@(x) [real(y(c(x))); imag(y(c(x)))];
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5])
fprintf('===================\n');
% solution of 2 equations: Re c^2 + 1; Im c^2 = 0;
c = @(x) complex(x(1),x(2))^2;
fx = @(x) [real(c(x))+1; imag(c(x))];
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5])
The first solution corresponds the example solved by fminsearch, however, with smaler tolerances. The solution is the same.
If you wanted to solve the >>complex<< problem f(x) = x^2 + 1, then the anonymous functionsare different, and are given in example 2 and 3. It is clear that the almost exact solution is reached in only 4 steps (cnt).
All the best in the New Year!
Miroslav

Dear Prof. Balda
Happy New Year
I have a question form the LMFnlsq:
Currently I am working on a problem that I should numerically solve a nonlinear equation, that the result will be complex numbers. I googles it and then there are two solution I have found;
One of them is with your code and the other one is with the fminsearch:
I checked the solutions for the simple problem:
“
clc
clear all
close all
y =@(x) x^2+1;
c =@(x) complex(x(1),x(2));
fx=@(x) abs(y(c(x)));
[x,ssq,cnt] = LMFnlsq(fx,[0.1;1.5])
[sol,fval]=fminsearch(fx,[0.1;1.5])
“
The results of the above equation are:
“
x =
-0.0004
1.0009
ssq =
4.1579e-06
cnt =
93
sol =
0.0000
1.0000
fval =
6.7954e-05
“
I wondering that it is possible to use your code in this case and any special option should be chosen for that?
Thank you very much
Best Regards

Comment only