Ask Your Question

# roriiz's profile - activity

 2016-06-01 10:38:26 -0500 asked a question iteration problem def valores(f,p,a,b,xi,n): var('k,xk,fi,ErAbs,ErRel,ErMet') a==a b==b xi==xi x1=p(xi) er= 0 ea= 0 em= 0 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)) print(l) print(l/(1-l)) show(valores(f,p,a,b,xi,n))  My problem here is that when i choose another values for n i would like to get this k values : k 0 1 2 and not as im getting : k 2 2 2 2016-06-01 10:31:10 -0500 received badge ● Scholar (source) 2016-06-01 10:18:03 -0500 commented answer fixed point iteration issue and on other values for n too if i choose n = 0 shows only this (k xk fi ErAbs ErRel ErMet) 2016-06-01 10:15:01 -0500 commented answer fixed point iteration issue 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 "", line 1, in File "_sage_input_127.py", line 10, in 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 File "/tmp/tmp50pxgy/___code___.py", line 4, in exec compile(u"_interact_.recompute('3')" + '\n', '', 'single') File "", line 1, in 2016-06-01 10:12:14 -0500 received badge ● Student (source) 2016-06-01 10:08:48 -0500 received badge ● Editor (source) 2016-06-01 10:06:26 -0500 asked a question fixed point iteration issue 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 "", line 1, in File "_sage_input_117.py", line 10, in 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 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