help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fminunc and for loop


From: Juan Pablo Carbajal
Subject: Re: fminunc and for loop
Date: Tue, 10 Jul 2012 19:34:59 +0200

On Tue, Jul 10, 2012 at 7:23 PM, Michael Teitelbaum
<address@hidden> wrote:
> Hi,
> I am trying to perform the fminunc function, but I want to use a for loop
> within my function, and I'm not sure exactly how to do that.
> What I want is:
>
> fminunc(f,[0,0])
> where f equals the sum of:
>
> f = @(x)((((A(i,3) / 1000 + x(1) + A(i,4) / 1000 - ((A(i,3) / 1000 + x(1) +
> A(i,4) / 1000) ^ 2 - 4 * A(i,3) / 1000 * A(i,4) / 1000) ^ 0.5) / 2 * 1.4e-3
> - (1.4e-3 - 8e-6) * (A(i-1,3) / 1000 + x(1) + A(i-1,4) / 1000 - ((A(i-1,3) /
> 1000 + x(1) + A(i-1,4) / 1000) ^ 2 - 4 * A(i-1,3) / 1000 * A(i-1,4) / 1000)
> ^ 0.5) / 2) * x(2)) * 1e6 - A(i,1)) ^ 2
>
> for i between 5 and  35.
>
> If it is not possible to use a for loop within fminunc, is there a good way
> to get octave to write out that function for me instead of me having to
> write it out manually?
>
> Any help would be greatly appreciated.
> Thanks,
> Michael
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

You can create a function (not a anonymous one)

function v = my_func(x,A)
 %% Do your magic here
endfunction

and then define A and call
fminunc(@(x)my_func(x,A),[0,0])

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]