simpsons-rule

MATLAB Simpson's 1/3 Rule and Romberg

会有一股神秘感。 提交于 2020-02-08 06:17:12
问题 I'm just starting to learn MATLAB. The purpose of the exercise is to approximate/integrate using Simpson's 1/3 rule and romberg. The problem is to integrate x^(1/2) from 0 to 2 When I execute: simpson(fun,0,2,10) I get an error on line 2: fun = x^(1/2); or on line 16 of simpson: f = feval(fun,x); Thanks for the help! Here is my equation code: function [fun] = ff(x) fun = x^(1/2); end My simpson code: function I = simpson(fun,a,b,npanel) % Multiple Segment Simpson's rule % % Synopsis: I =

Python numerical integration with Simpson's rule

泄露秘密 提交于 2019-12-31 02:01:13
问题 I have started to work through this book (Computational Physics Exercise 5.4) and its exercises and I got stuck with the following question: Write a Python function J(m,x) that calculates the value of Jm(x) using Simpson’s rule with N = 1000 points. Use your function in a program to make a plot, on a single graph, of the Bessel functions J0, J1, and J2 as a function of x from x = 0 to x = 20. I have created the following code to evaluate the first part of the question but not sure if even

Python numerical integration with Simpson's rule

人盡茶涼 提交于 2019-12-01 20:42:21
I have started to work through this book ( Computational Physics Exercise 5.4 ) and its exercises and I got stuck with the following question: Write a Python function J(m,x) that calculates the value of Jm(x) using Simpson’s rule with N = 1000 points. Use your function in a program to make a plot, on a single graph, of the Bessel functions J0, J1, and J2 as a function of x from x = 0 to x = 20. I have created the following code to evaluate the first part of the question but not sure if even this is correct: def f(x, t): return 1 / pi * (math.cos(x - t * math.sin(x))) def float_range(a, b, c):