Ask Your Question
1

fixed point iteration issue [closed]

asked 2016-06-01 17:04:15 +0100

roriiz gravatar image

updated 2016-06-01 17:14:04 +0100

tmonteil gravatar image

Im having a problem with this code wonder if someone could help me, its a code for fixed point iteration:

def valores(f,p,a,b,xi,n):
    var('k,xk,fi,ErAbs,ErRel,ErMet')
    a==a
    b==b
    xi==xi
    x1=p(xi)
    L=[[k,xk,fi,ErAbs,ErRel,ErMet]]
    for i in range (0,n):
        L.append([n,xi,x1,er,ea,em])
        er = abs(x1-xi)
        if xi > 1:
            ea = er/xi
        else:
            ea = er
        em = ea*(l*(1-l))
        xi=p(xi)
        x1 = p(xi)
    return (matrix(L))

@interact
def Exp(n = selector(range(0, 11),nrows=1, label="Botão"),f = input_box(default=x*e^x-1), a = input_box(default=0.5), b = input_box(default=1), xi = input_box(default=0.8),p = input_box(default=e^(-x)):
    df = diff(f,x)
    dp = diff(p,x)
    if df(x) > 0:
        l = abs(dp(b))
    else:
        l = abs(dp(a))
    show(valores(f,p,a,b,xi,n))

Error showed:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_117.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QGludGVyYWN0CmRlZiBF\ eHAobiA9IHNlbGVjdG9yKHJhbmdlKDAsIDExKSxucm93cz0xLCBsYWJlbD0iQm90w6NvIiks\ ZiA9IGlucHV0X2JveChkZWZhdWx0PXgqZV54LTEpLCBhID0gaW5wdXRfYm94KGRlZmF1bHQ9\ MC41KSwgYiA9IGlucHV0X2JveChkZWZhdWx0PTEpLCB4aSA9IGlucHV0X2JveChkZWZhdWx0\ PTAuOCkscCA9IGlucHV0X2JveChkZWZhdWx0PWVeKC14KSk6CiAgICBkZiA9IGRpZmYoZix4\ KQogICAgCiAgICBkcCA9IGRpZmYocCx4KQogICAgCiAgICBpZiBkZih4KSA+IDA6CiAgICAg\ ICAgbCA9IGFicyhkcChiKSkKICAgIGVsc2U6CiAgICAgICAgbCA9IGFicyhkcChhKSkKICAg\ ICAgICAKICAgIHNob3codmFsb3JlcyhmLHAsYSxiLHhpLG4pKQ=="),globals())+"\\n")\ ; execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpWfUq28/___code___.py", line 4 def Exp(n = selector(range(_sage_const_0 , _sage_const_11 ),nrows=_sage_const_1 , label="Botão"),f = input_box(default=x*e**x-_sage_const_1 ), a = input_box(default=_sage_const_0p5 ), b = input_box(default=_sage_const_1 ), xi = input_box(default=_sage_const_0p8 ),p = input_box(default=e**(-x)): ^ SyntaxError: invalid syntax
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by roriiz
close date 2016-06-01 17:31:58.036851

1 Answer

Sort by » oldest newest most voted
0

answered 2016-06-01 17:11:49 +0100

tmonteil gravatar image

One closing parenthesis is missing at the end of the line defining your interact Exp:

It should be (three closing parentheses):

def Exp(n = selector(range(0, 11),nrows=1, label="Botão"),f = input_box(default=x*e^x-1), a = input_box(default=0.5), b = input_box(default=1), xi = input_box(default=0.8),p = input_box(default=e^(-x))):
edit flag offensive delete link more

Comments

that was actually a error but still getting a error when i chose n = 1 on the button it shows this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_127.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("X2ludGVyYWN0Xy51cGRh\ dGUoJzMnLCAnbicsIDEsIF9pbnRlcmFjdF8uc3RhbmRhcmRfYjY0ZGVjb2RlKCdNUT09Jyks\ IGdsb2JhbHMoKSkKX2ludGVyYWN0Xy5yZWNvbXB1dGUoJzMnKQ=="),globals())+"\n")\ ; execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module>

File "/tmp/tmp50pxgy/___code___.py", line 4, in <module> exec compile(u"_interact_.recompute('3')" + '\n', '', 'single') File "", line 1, in <module>

roriiz gravatar imageroriiz ( 2016-06-01 17:15:01 +0100 )edit

and on other values for n too if i choose n = 0 shows only this

(k xk fi ErAbs ErRel ErMet)

roriiz gravatar imageroriiz ( 2016-06-01 17:18:03 +0100 )edit

Question Tools

Stats

Asked: 2016-06-01 17:04:15 +0100

Seen: 740 times

Last updated: Jun 01 '16