On Tue, Jul 10, 2012 at 3:26 PM, Jordi Gutiérrez Hermoso
<address@hidden> wrote:
On 10 July 2012 14:32, Michael Teitelbaum <
address@hidden> wrote:
> Jordian method:
> I received the following error when I inputted your code:
> error: `x' undefined near line 2 column 29
> error: called from:
> error: midterm at line 2, column 5
> error: evaluating argument list element number 1
> error: f at line 5, column 5
> error: /sw/share/octave/3.6.1/m/optimization/fminunc.m at line 149, column
> 6
Ah, oops, the midterm function calls are missing an x parameter,
midterm(A,idx,x) and midterm(A,prev,x);
> Was your code meant to be put directly into octave, or was it kind
> of just a general idea of the type of thing I should try?
A bit of the latter. I was trying to give structure to the programming
task you attempted.
> I don't know enough about programming to write something similar to
> what you sent me.
I'm always distraught a little when people program in Octave and say
they don't know programming or they are not programmers.
Octave code is not black magic you shouldn't attempt to understand.
Octave is a programming language, and the only way to use Octave is to
write and understand programs. If you can do mathematics (and
apparently you can), you can also program.
Do read the Octave manual. It's meant to be pedagogical:
http://www.gnu.org/software/octave/doc/interpreter/
HTH,
- Jordi G. H.
1;
function out = midterm(A, idx, x)
out = \
A(idx,3) + A(idx,4) + x(1) \
- ( (A(idx,3) + A(idx,4) + x(1)).^2 \
- 4*A(idx,3).*A(idx,4)).^.5;
endfunction
function out = f(A, x)
## Define indices of interest
idx = 5:35;
prev = idx-1;
## Scale the two columns that require it
A(5:35,3:4) /= 1000;
## Compute the desired sum of squares objective function
out = sumsq(1e6*x(2)*(midterm(A,idx,x)/2.4e-3
- 6.96e-4*midterm(A,prev,x))
- A(idx,1));
endfunction
result = fminunc(@(x) f(A,x), [0,0])
--
DAS
https://linuxcounter.net/user/206392.html