请输入您要查询的字词:

 

单词 CodeForSimpsonsRule
释义

code for Simpson’s rule


Python code for Simpson’s rule

\\PMlinkescapetext{from math import *def f(x):  #function to integrate  return sin(x)def simpson_rule(a,b):  #Approximation by Simpson's ruleMathworldPlanetmath  c=(a+b)/2.0  h=abs(b-a)/2.0  return h*(f(a)+4.0*f(c)+f(b))/3.0# Calculates integral of f(x) from 0 to 1print simpson_rule(0,1)}

Integrating sinx from 0 to 1 with the previous code gives 0.45986218971 whereas the true value is 1-cos1=0.459697694131860282599063392557.

随便看

 

数学辞典收录了18232条数学词条,基本涵盖了常用数学知识及数学英语单词词组的翻译及用法,是数学学习的有利工具。

 

Copyright © 2000-2023 Newdu.com.com All Rights Reserved
更新时间:2025/5/4 19:52:41