help-octave
[Top][All Lists]
Advanced

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

Re: Another fsolve question -- Beginner


From: Przemek Klosowski
Subject: Re: Another fsolve question -- Beginner
Date: Thu, 26 May 2011 17:17:12 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10

On 05/26/2011 01:04 PM, MMolloy wrote:
Hi all,

I have had a look and can't seem to find a post which answers my question -
apologies if there is one. My question is probably pretty simple but I'm
having a hard time of it because I'm new to Octave - especially functions in
Octave.

I'm running;
Ubuntu Lucid x64
Octave 3.2.3 for x86_64-pc-linux-gnu.

The problem:

function y = f (x)
y = zeros(10,1)
load E1.csv;
for i=1:10
y(i) = (1.14.*exp(-x(i)./1.14)) .- (3.79.*exp(-x(i)./3.79)) .- E1(i)
endfor
endfunction
load RG1.csv
[x, fval, info] = fsolve(@f, RG1);

OK, but consider that the solver executes your function repeatedly, so the file E1.csv is being re-read continuously, which has got to hurt the execution time. Read it once into a global variable, and use 'global E1' within the function f() and in the main function.

Also, end your lines in semicolons, because otherwise you get printouts of computed values from those lines.

Also, you're working too hard: your 1:10 loop with element-by-element operations should use Octave's vectorized notation,
 y=(0.1.*exp(-x./0.1)) - (0.33.*exp(-x/0.33)) - E;

My problem is that the matrices for B and E (which I compute elsewhere) have
a size of [10000,1]. So when I use this;

I think that maybe all this re-reading is leaking some temporary storage. Please try rewriting the code and report back if it helped; if it didn't, please provide the data so that we can run your code for ourselves to see what is happening.


reply via email to

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