Fixed point iteration issue
Show older comments
Need help to find the error its not matlab its sagemath, i couldnt find any forum of sagemath that worked. would apreciate any help.
sage: def valores2(f,p,a,b,x,n): ... var('k,xk,fi(xk),Er.Abs,Er.Rel,Er.Met') ... x==x ... a == a ... b == b ... ... Z=[[k,xk,fi(xk),Er.Abs,Er.Rel,Er.Met]] ... for i in range (0,n): ... Z.append([i,x,p(x),ea,er,em]) ... ... if f(a)*f(b)<0: ... print("check") ... else: ... print("not check") ... ... ... ... er = abs(p(x)-x) ... ... if x > 1: ... ea = er/x ... else: ... ea = er ... ... ... df = diff(f,x) ... ... dp = diff(p,x) ... ... ... if df(x) > 0: ... l = abs(dp(b)) ... else: ... l = abs(dp(a)) ... ... em = ea*(l*(1-l)) ... ... ... x=p(x) ... ... ... return (matrix(Z)) sage: @interact sage: def Exp(n = selector(range(0, 11),nrows=1, label="Botão"),f = input_box(default=x*e^x -1), x = input_box(default=0.8), p = input_box(default=e^(-x)), a = input_box(default=0.5), b = input_box(default=1)): ... ... show(valores2(f,p,a,b,x,n))
#######----ERROR-----######
Traceback (most recent call last): File "<stdin>", line 1, in module File "_sage_input_5.py", line 10, in module exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + support.preparse_worksheet_cell(base64.b64decode("X2ludGVyYWN0Xy5yZWNv\ bXB1dGUoJzMxJyk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in module
File "/tmp/tmp4lQStw/___code___.py", line 2, in <module>
exec compile(u"_interact_.recompute('31')" + '\n', '', 'single')
File "", line 1, in <module>
File
"/home/sage/sage-6.3/local/lib/python2.7/site-packages/sagenb-0.10.8.2-p\
y2.7.egg/sagenb/notebook/interact.py", line 3892, in recompute
S['function']()
File
"/home/sage/sage-6.3/local/lib/python2.7/site-packages/sagenb-0.10.8.2-p\
y2.7.egg/sagenb/notebook/interact.py", line 2674, in _
z = f(*[variables[arg] for arg in args])
File "/tmp/tmpySnhLB/___code___.py", line 6, in Exp
show(valores2(f,p,a,b,x,n))
File "/tmp/tmpNEoaxc/___code___.py", line 4, in valores2
var('k,xk,fi(xk),Er.Abs,Er.Rel,Er.Met')
File "var.pyx", line 139, in sage.calculus.var.var
(build/cythonized/sage/calculus/var.c:1033)
File "ring.pyx", line 595, in sage.symbolic.ring.SymbolicRing.var
(build/cythonized/sage/symbolic/ring.cpp:7913)
File "ring.pyx", line 643, in sage.symbolic.ring.SymbolicRing.var
(build/cythonized/sage/symbolic/ring.cpp:7657)
ValueError: The name "fi(xk)" is not a valid Python identifier.
Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!