[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to implement a summation function for numerical solving?
From: |
andrewcd |
Subject: |
Re: How to implement a summation function for numerical solving? |
Date: |
Wed, 15 Jun 2011 07:21:12 -0700 (PDT) |
Thanks everybody for all of your help so far. Now I have a new problem --
fsolve is highly sensitive to the initial "guess" vector. I guess that it
is not iterating enough, or something. Or, since it is guessing at the
value of an exponent, small changes by its standards lead to big changes in
my results. Any thoughts on how I can get around this? Increase the number
of iterations somehow? Or is there a different way to solve simultaneous
nonlinear equations?
To get a flavor for my problem, try to run my code below, using guess =
[.5,0] and guess = [0,0]. The code *should* eventually spit out a normal
curve with a mean and variance of 2. But the wrong guess gives the wrong
curve.
Thanks again, and thanks in advance.
Code:
------------------------------------------------------------------------------------------------
clear all
global mu;
global x;
global lx;
global xmin;
global variance;
AT = .5;
xmin = -10;
xmax = 10;
stp = .1;
x = xmin:stp:xmax;
lx = length(x);
mu = 2;
variance = 2;
guess = [.5,0]
function fcns = eqns(z);
global x;
global lx;
global mu;
global variance;
lam1=z(1);
lam2=z(2);
f1 = x;
f2 = (x-mu).^2;
p = exp(-lam1*f1 - lam2*f2) ;
fcns = [(f1-mu)*p', (f2-variance)*p'];
end
result = fsolve(@eqns, guess)
p = e.^(-result(1)*x - result(2)*(x-mu).^2);
Z = sum(p);
P=p./Z;
plot( x, P);
sum(P)
axis([xmin-1,xmax+1,0,max(P)*2])
c = cumsum(P);
for n = 1:length(c);
if c(n)<AT;
EV(n) = c(n);
endif
end
L = length(EV);
EV = stp*L+xmin
--
View this message in context:
http://octave.1599824.n4.nabble.com/How-to-implement-a-summation-function-for-numerical-solving-tp3593289p3599517.html
Sent from the Octave - General mailing list archive at Nabble.com.
- How to implement a summation function for numerical solving?, andrewcd, 2011/06/13
- Re: How to implement a summation function for numerical solving?, Liam Groener, 2011/06/13
- Re: How to implement a summation function for numerical solving?, andrewcd, 2011/06/13
- Re: How to implement a summation function for numerical solving?, andrewcd, 2011/06/14
- Re: How to implement a summation function for numerical solving?, Kimmo Luoma, 2011/06/14
- Re: How to implement a summation function for numerical solving?, John W. Eaton, 2011/06/14
- Re: How to implement a summation function for numerical solving?,
andrewcd <=
- Re: How to implement a summation function for numerical solving?, Liam Groener, 2011/06/16
- Re: How to implement a summation function for numerical solving?, Liam Groener, 2011/06/16
- Re: How to implement a summation function for numerical solving?, andrewcd, 2011/06/16