help-octave
[Top][All Lists]
Advanced

[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.

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]
{"ft_lang_label":"__label__en","ft_lang_prob":0.71851814,"math_prob":0.9839917,"size":2857,"snap":"2019-13-2019-22","text_gpt3_token_len":836,"char_repetition_ratio":0.2166141,"word_repetition_ratio":0.2551724,"special_character_ratio":0.3479174,"punctuation_ratio":0.20975609,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9963903,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-05-24T02:20:36Z\",\"WARC-Record-ID\":\"<urn:uuid:4a06d49c-a192-4004-a313-2c43693f3416>\",\"Content-Length\":\"8072\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fd5b97c5-5b51-42dd-ae3b-1319f31d79f6>\",\"WARC-Concurrent-To\":\"<urn:uuid:da967edb-6c9a-4205-b915-10b7eb9e7ce6>\",\"WARC-IP-Address\":\"209.51.188.17\",\"WARC-Target-URI\":\"http://lists.gnu.org/archive/html/help-octave/2011-06/msg00101.html\",\"WARC-Payload-Digest\":\"sha1:G5TH7GEFHVSH6BBICK6YIS32X7D3UIEN\",\"WARC-Block-Digest\":\"sha1:FMUH2QZGFKPTRT242J43BTLSMSOU7E32\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-22/CC-MAIN-2019-22_segments_1558232257481.39_warc_CC-MAIN-20190524004222-20190524030222-00521.warc.gz\"}"}