How to resolve the algorithm Numerical integration step by step in the Ursala programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Numerical integration step by step in the Ursala programming language
Table of Contents
Problem Statement
Write functions to calculate the definite integral of a function ƒ(x) using all five of the following methods: Your functions should take in the upper and lower bounds (a and b), and the number of approximations to make in that range (n). Assume that your example already has a function that gives values for ƒ(x) . Simpson's method is defined by the following pseudo-code:
Demonstrate your function by showing the results for:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Numerical integration step by step in the Ursala programming language
Source code in the ursala programming language
#import std
#import nat
#import flo
(integral_by "m") ("f","a","b","n") =
iprod ^(* ! div\float"n" minus/"b" "a",~&) ("m" "f")*ytp (ari successor "n")/"a" "b"
(integral_by "m") ("f","a","b","n") =
iprod ^(* ! div\float"n" minus/"b" "a",~&) ^H(*+ "m"+ -:"f"+ * ^/~& "f",~&ytp) (ari successor "n")/"a" "b"
left = integral_by "f". ("l","r"). "f" "l"
right = integral_by "f". ("l","r"). "f" "r"
midpoint = integral_by "f". ("l","r"). "f" div\2. plus/"l" "r"
trapezium = integral_by "f". ("l","r"). div\2. plus "f"~~/"l" "r"
simpson = integral_by "f". ("l","r"). div\6. plus:-0. <"f" "l",times/4. "f" div\2. plus/"l" "r","f" "r">
#cast %eL
examples = <.left,midpoint,rignt,trapezium,simpson> (sqr,0.,pi,10)
You may also check:How to resolve the algorithm Day of the week step by step in the Lingo programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Joy programming language
You may also check:How to resolve the algorithm Verify distribution uniformity/Chi-squared test step by step in the VBA programming language
You may also check:How to resolve the algorithm Matrix digital rain step by step in the Rust programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Phixmonti programming language