简体   繁体   中英

Solving an equation iteratively on Python

The question is:

Determine at which point the function y=xe(x^2) crosses the unit circle in the x-positive, y-positive quadrant.

Rewrite the problem as a fix-point problem, ie in the form x=F(x)

This equation can be solved iteratively: x_n=F(x_n−1)

Implement the above equation into a function fixpoint that takes as argument the initial guess x0 and the tolerance tol and returns the sequence xn of approximations to x.

I'm very new to python, and I've rewritten the equations as

xn=1/(np.sqrt(1+np.exp(2(x0)**2)))

and created a function, but I'm genuinely not too sure how to go about this.

It genuinely is not our issue if you don't understand the language or the problem you are trying to solve.

This looks like homework. You don't learn anything if somebody here does it for you.

Try to solve an iteration or two by hand with calculator, pencil, and paper before you program anything.

Your first equation looks wrong to me.

xn=1/(np.sqrt(1+np.exp(2*(x0)**2)))

I don't know if you forgot a multiplication sign between the two arguments to the exponential function. You should check.

I would prefer x0*x0 to x0**2 . Personal taste.

I would expect to see an equation that would take in x(n) and return x(n+1). Yours will never use the new value x(n) to get x(n+1). You're stuck with x(0) as written.

I would expect to see a loop where the initial value of x(n) is x(0). Inside the loop I'd calculate x(n+1) from x(n) and check to see if it's converged to a desired tolerance. If it has, I'd exit the loop. If it has not, I'd update x(n) to equal x(n+1) and loop again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM