A list of puns related to "Trapezoidal rule"
Here :
At page 5, he suddenly starts to use a function G.
Where does come that new function of "G(x) = f (x) β S(x) β q(x β x jβ1)(x β x j ) " ?
What's the relationship of G(x) to f(x) and S(x) ?
import sympy as sym
from sympy.abc import x
def trapizodial_rule(b,a,n):
delta_x=(b-a)/(n)
print(delta_x)
a=a-delta_x
subinterval=[]
import math
integrand= (math.e**x)*(x**3)+(1/(4*x**0.5))
while a + delta_x <= b:
a = delta_x + a
subinterval.append(a)
list1=[]
for n in range(0,n):
f1=integrand.subs(x,subinterval[n])
list1.append(f1)
list2=[]
for n in range(1,len(list1)-1):
f2=2*list1[n]
list2.append(f2)
middleterm = sum(list2)
outerterm = list1[0] + list1[n+1]
traprule=((delta_x/2)*(middleterm + outerterm))
print(traprule)
the correct output is around 16 million but I got around 9 million I have another program that is almost exactly like this but the indexes for some of the lists are a little different because the subinterval list could have an even or an odd number of items. the other program gives the correct approximation for the integrand x^3 on the interval [2,4]. I'm up for any suggestions because the goal is to have any integrand to be approximated not just x^3
Is it okay to directly place the long summations in pm solver? need help from mods
I made a program in python for the trapezoidal rule and want to make a graph that shows the approximation error, approximation, and true value. The problem is that I donβt know the terminology for what that type of graph would be called. I was going to use matlibplot but I donβt know what the appropriate graph to use. I think it would be cool to make a graph but I need help. Any suggestions would be greatly appreciated.
How would I be able to do the trapezoidal rule for example in the integral of x^2+1/x+1 -tanx/x+2 from -4 to 5 with 3 sub intervals? It would have an undefined value when at the -1 value.
Hello,
I've got the trapezoidal rule where func
is a function declared in the program.
// multi application trapezoidial rule
double trap(double a, double b, double (* func)(double), int segments){
double integral = func(a) + func(b);
double h = (b-a)/n;
for (int i = 1; i < n; i++){
integral += 2 * func(a + i*h);
}
integral *= (b-a) / (2*n);
return integral;
}
How can I convert this if I am given the following table of answers instead of a function:
x | 0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|---|
f(x) | 0 | 2.4 | 2.67 | 2.2 | 1.9 | 0 |
I've stored this table in a struct of x and y.
%Trapezoidal
f =@(x) 1-exp(-x);
I= trap(f(x),0, 4);
function I=trap(func,a,b,n,varargin)
if nargin<3
error('at least 3 inputs required');
end
if ~(b>a)
error('upper bound must be greater than lower')
end
if nargin<4||isempty(n)
n=100;
end
x=a;
h=(b-a)/n;
s=func(a,varargin{:});
for i=1 : n-1
x=x+h;
s=s+2*func(x,varargin{:});
end
s=s+func(b,varargin{:});
I=(b-a)*s/(2*n);
end
I keep getting this error
Array indices must be positive integers or logical values.
Error in sym/subsref (line 900)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in ICA_9>trap (line 24)
s=func(a,varargin{:});
Error in ICA_9 (line 7)
I= trap(f(x),0, 4);
I honestly don't know what's wrong it can someone please point me to the right direction?
What does the k variable represent in the trapezoidal rule?
https://preview.redd.it/f1rr9rspjk451.png?width=511&format=png&auto=webp&s=9349834db098074f45655c891847b500ec3369cd
Thanks!
So Iβm trying to do a question using the trapezoidal rule (question 2)
https://imgur.com/a/uP41PaT
I havenβt done a question that has dx in the numerator before (dx is usually written to the side like in question 1). I was wondering if we would just treat this as if the numerator is 1 or if not, how would I solve?
Update: I got it right.
I had a question like this on my test a few classes ago and was unsure how to do it. Thanks!
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.