help-octave
[Top][All Lists]
Advanced

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

Another fsolve question -- Beginner


From: MMolloy
Subject: Another fsolve question -- Beginner
Date: Thu, 26 May 2011 10:04:43 -0700 (PDT)

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);

So basically I want to solve, for x, an equation which is the difference of
two exponentials, ie.

0 = exp(-x/a) - exp(-x/b) - c

This I can do for single values or even matrices:

function y = f (x)
y = zeros(2,1)
A = [0.6899;0.93388]
E = ((A./4.36261).-0.33).+0.1
for i=1:2
y(i) = (0.1.*exp(-x(i)./0.1)) .- (0.33.*exp(-x(i)./0.33)) .- E(i)
endfor
endfunction
RG = [0.3;0.5];
[x, fval, info] = fsolve(@f, RG);

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;

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

It seems to be working but very quickly eats up all my RAM until the
computer freezes. I've tried splitting my matrices into [1,1] size .csv
files so that the memory is cleared, calling each one in successive
iterations like this:

for i=0:9999
function y = f (x)
y = 0
eval(['E1 = load("E_' num2str(i) '");']);
y(1) = (1.14.*exp(-x(1)./1.14)) .- (3.79.*exp(-x(1)./3.79)) .- E1
endfunction
eval(['b = load("RG_' num2str(i) '")']);
[x, fval, info] = fsolve(@f, b);
eval(['dlmwrite("x_' num2str(i) '", x);']);
eval(['dlmwrite("ref_' num2str(i) '", i);']);
clear
endfor

which gives me the error:

"error: load: unable to find file E_0+1i".

How can I put each guess at "x" (RG in the above) along with it's
corresponding "E1" value into each iteration of the problem?

There's probably some simple solution (i hope!) - Any advice would be
greatly appreciated!

Matt.

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Another-fsolve-question-Beginner-tp3553080p3553080.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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