0

I tried to apply the method posted in Find positive solutions to undetermined linear system of equations to the set

A=[0 0.0992 0.315 0.619 1; 0 0.248 0.315 0.248 0]; b=[0.1266 0.4363].

It is supposed that there exists a positive and constrained solution to this problem. The worst thing is that I have an answer code but I can't make it work because my Matlab version doesn`t recognize the anonymous function call and some instructions are obscure for me. Here is the code:

% example_pt_source_atmos_setup.m
% determine geometry
D2 = 0.5; % diameter of the observation aperture [m]
wvl = 1e-6; % optical wavelength [m]
k = 2*pi / wvl; % optical wavenumber [rad/m]
Dz = 50e3; % propagation distance [m]
% use sinc to model pt source
DROI = 4 * D2; % diam of obs-plane region of interest [m]
D1 = wvl*Dz / DROI; % width of central lobe [m]
R = Dz; % wavefront radius of curvature [m]
% atmospheric properties
Cn2 = 1e-16; % structure parameter [m^-2/3], constant
% SW and PW coherence diameters [m]
r0sw = (0.423 * k^2 * Cn2 * 3/8 * Dz)^(-3/5);
r0pw = (0.423 * k^2 * Cn2 * Dz)^(-3/5);
p = linspace(0, Dz, 1e3);
% log-amplitude variance
rytov = 0.563 * k^(7/6) * sum(Cn2 * (1-p/Dz).^(5/6) ...
.* p.^(5/6) * (p(2)-p(1)));
% screen properties
nscr = 11; % number of screens
A = zeros(2, nscr); % matrix
alpha = (0:nscr-1) / (nscr-1);
A(1,:) = alpha.^(5/3);
A(2,:) = (1 - alpha).^(5/6) .* alpha.^(5/6);
b = [r0sw.^(-5/3); rytov/1.33*(k/Dz)^(5/6)];
% initial guess
x0 = (nscr/3*r0sw * ones(nscr, 1)).^(-5/3);
% objective function
fun = @(X) sum((A*X(:) - b).^2);
% constraints
x1 = zeros(nscr, 1);
rmax = 0.1; % maximum Rytov number per partial prop
x2 = rmax/1.33*(k/Dz)^(5/6) ./ A(2,:);
x2(A(2,:)==0) = 50^(-5/3)
[X,fval,exitflag,output] ...
= fmincon(fun,x0,[],[],[],[],x1,x2)
% check screen r0s
r0scrn = X.^(-3/5)
r0scrn(isinf(r0scrn)) = 1e6;
% check resulting r0sw & rytov
bp = A*X(:); [bp(1)^(-3/5) bp(2)*1.33*(Dz/k)^(5/6)]
[r0sw rytov]

Thanks for your attention. Carolina Rickenstorff

  • 1
    It looks like ther may be a question hidden in this post somewhere, but I cant find it. Can you elaborate? – Ander Biguri May 06 '15 at 12:15
  • are you referring to [this](http://stackoverflow.com/questions/16365723/find-positive-solutions-to-underdetermined-linear-system-of-equations) question? how is the linear system of equation you give related to the code below? – m.s. May 06 '15 at 12:29
  • I mean, I pasted that code into my Matlab version 6.5 and doesn't run. I think that there is a way to solve it without reinstalling a newer Matlab. – Carolina Rickenstorff May 06 '15 at 16:39
  • I pasted that code into my Matlab 6.5 and doesn`t work. I know that my objective function is sum((A*x(:)-b).^2) but my version doesn`t recognize the anonymous function syntax. Is there a way to solve it without reinstalling a newer Matlab? – Carolina Rickenstorff May 06 '15 at 17:29
  • You can turn the anonymous function into a regular function, and pass a function handle as `@functionname`. – buzjwa May 06 '15 at 19:48
  • I tried to declare the objective function as a separate m.file as sum((A*X(:) - b).^2). When I run the program it tells me that A and b are not defined. The examples in Matlab help show functions involving x only. I really don`t know how to declare my objective function. I request help. – Carolina Rickenstorff May 07 '15 at 07:33
  • I'm not sure if this was around in MATLAB 6.5, but try using [nested functions](http://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html). Have your objective function defined in the same file as your code (not in a separate file) and then the function can access the variables in the outside code. – buzjwa May 07 '15 at 11:31
  • Thanks Naveh, I reformulate my problem under the question title: defining a function handle matlab 6.5. Can you take a look, please? – Carolina Rickenstorff May 07 '15 at 13:03

0 Answers0