|
|
Trapezium rule
Hi, I'm a complete noob to matlab and am trying to write a program for the trapezium rule for (x^2+2*x)*sin(x), but I keep getting the error message:
??? Error: File: trap2.m Line: 16 Column: 68
Unbalanced or unexpected parenthesis or bracket.
Here is my program:
% trapeziumrule.m test program for numerical integration using the composite
% trapezium rule to solve the integral of (x^2+2*x)*sin(x) between a and b
clear;
format long;
% So matlab can use more decimal places
a=input('input a (Please Write an end value ->');
b=input('input b (Please Write an end value) ->');
n=input('The number of intervals (n) ->');
%I have used this function so we can input the values for a, b and n in the
%command window once we have ran the trapeziumrule.m file.
h=(b-a)/n;
fa=(a^2+2*a)*sin(a); % f(a)
fb=(b^2+2*b)*sin(b); %f(b)
ff=0;
for i=2:n
ff=ff+(2*(((a+(h*(i-1))))^2+2*((a+(h*(i-1)))))*sin(((a+(h*(i-1))))); % sum of 2f(a+i(h)) where i=1 to n-1
end
result=(h/2)*(fa+fb+ff);
% result=f(a)+f(b)+ sum of 2f(a+i(h)) where i=1 to n-1
could someone help me with where I am going wrong please?
Many thanks.
|
|
0
|
|
|
|
Reply
|
Sarah
|
12/8/2010 10:00:23 PM |
|
On 10-12-08 04:00 PM, Sarah wrote:
> ff=ff+(2*(((a+(h*(i-1))))^2+2*((a+(h*(i-1)))))*sin(((a+(h*(i-1))))); %
You have a '(' before the '2*' but that bracket is not closed anywhere. How
far did you want that expression to extend? If you want it to extend to the
end of line, then as all of the operations at the same level from that point
on are multiplications, the '(' before the '2*' would be redundant; the same
if you want it to close just before the '*sin'. Without disturbing the flow of
the subexpressions, at the moment I cannot see any place to put the ')' that
would not make the '(' ')' pair redundant.
|
|
0
|
|
|
|
Reply
|
Walter
|
12/8/2010 10:37:28 PM
|
|
|
1 Replies
419 Views
(page loaded in 0.026 seconds)
Similiar Articles: Trapezium rule - comp.soft-sys.matlabHi, I've been working on this problem for quite a while but really not sure whether my approach is correct. I'm looking to create an mfile to perfo... Trapezium rule - comp.soft-sys.matlabHi, I'm a complete noob to matlab and am trying to write a program for the trapezium rule for (x^2+2*x)*sin(x), but I keep getting the error message: ... Trapezium Rule with Varying Strip Widths - comp.soft-sys.matlab ...I'm really stuck trying to work out this problem. I have an integral ∫1/x dx (between 1 and 101), and I want to use the trapezium rule to es... Trapezoidal Rule and Error? - comp.soft-sys.matlabI need to devise an integration method for computing the values of the function F(x) =int(exp(-x^2)), a and b are 0 and x, respectively. For this... Trapezoidal Rule in MATLAB. - comp.soft-sys.matlabHi, I'm trying to integrate the following function: 20/(1+x^2) in MATLAB using the trapezoidal rule ( not using the Matlab function 'trapz'). ... 50g and midpoint, trapezoid and Simpson's rules - comp.sys.hp48 ...on the 50 g is it possible to do the midpoint, trapezoid and Simpson's rule, and if so how can I do this. This is for my calculus 2 class. ... help for Forward rectangular rule in matlab - comp.soft-sys.matlab ...Trapezium rule - comp.soft-sys.matlab help for Forward rectangular rule in matlab - comp.soft-sys.matlab ... Trapezium rule - comp.soft-sys.matlab help for Forward ... Simpson's 1/3rd Rule and 3/8th Rule - comp.soft-sys.matlab ...Trapezium rule - comp.soft-sys.matlab Simpson's 1/3rd Rule and 3/8th Rule - comp.soft-sys.matlab ... Trapezium rule - comp.soft-sys.matlab Simpson's 1/3rd Rule and 3/8th ... how to write a grammar rule with yacc/bison - comp.unix.programmer ...Trapezium rule - comp.soft-sys.matlab how to write a grammar rule with yacc/bison - comp.unix.programmer ... Howdy...I need to write a class that will take a java ... is a ... geometric summation in matlab - comp.soft-sys.matlabTrapezium Rule with Varying Strip Widths - comp.soft-sys.matlab ... geometric summation in matlab - comp.soft-sys.matlab Trapezium rule - comp.soft-sys.matlab geometric ... Trapezoidal rule - Wikipedia, the free encyclopediaIn numerical analysis, the trapezoidal rule (also known as the trapezoid rule or trapezium rule) is an approximate technique for calculating the definite integral The ... The Trapezium RuleLinks. Formula Sheet. Contact the Author. Terms & Disclaimer. Maths Notation. The Trapezium Rule. See also: Trapezium Rule, GCSE level. The trapezium rule is a way of ... 7/26/2012 8:17:34 AM
|
|
|
|
|
|
|
|
|