[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Another fsolve question -- Beginner
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Another fsolve question -- Beginner |
Date: |
Thu, 26 May 2011 15:47:02 -0500 |
On 26 May 2011 12:04, MMolloy <address@hidden> wrote:
> 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);
Do you understand what .- means? You don't need it here, or ever.
Furthermore, your for loop is completely unnecessary. Write instead
y = 1.14*exp( -x/1.14 ) - 3.79*exp( -x/3.79 ) - E1
Also, don't put the load inside your function. Each time fsolve needs
to do a function evaluation, it needs to call your function f, and
it's performing the load of E1.csv each time.
I also recommend you use a text editor that indents your code. Emacs
or Notepad++ are popular choices.
I think these suggestions might lead you to a solution of your actual
problem.
HTH,
- Jordi G. H.