日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow随笔-不动点迭代求一元方程

發布時間:2025/3/12 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow随笔-不动点迭代求一元方程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu Sep 6 10:16:37 2018不動點法求解f(x)=x """import tensorflow as tf import numpy as npdef f(x):y=tf.cos(x)+tf.sin(x)return ydef body(x,fx,tol,i,n):x=f(x)fx=f(x)return (tf.Print(x,[x],"x:"),tf.Print(fx,[fx],"fx:"),tf.Print(tol,[tol],"tol:"),tf.Print(i+1,[i],"i:"),tf.Print(n,[n],"n:"))def c(x,fx,tol,i,n):t1=tf.greater(tf.abs(tf.subtract(fx,x)),tol)t2=tf.less(i,n)return tf.logical_and(t1,t2)x = tf.placeholder(tf.float32,shape=(),name="myx") tol= tf.placeholder(tf.float32,shape=(),name="mytol") fx = tf.constant(0,dtype=tf.float32,name="myfx") i = tf.constant(0,dtype=tf.int32,name="myi") n = tf.constant(0,dtype=tf.int32,name="myn")input_dict={x:0.,fx:np.cos(0)+np.sin(0),tol:1e-8,i:0,n:100} res = tf.while_loop(c, body, loop_vars=[x,fx,tol,i,n])with tf.Session() as sess: y=sess.run(res,feed_dict=input_dict)print y

tol:[1e-08]
x:[1.25872827]
fx:[1.25872803]
n:[100]
i:[98]tol:[1e-08]x:[1.25872803]
fx:[1.25872827]

n:[100]
x:[1.25872827]i:[99]tol:[1e-08]
fx:[1.25872803]

(1.2587283, 1.258728, 1e-08, 100, 100)

總結

以上是生活随笔為你收集整理的tensorflow随笔-不动点迭代求一元方程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。