COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Trapezium rule

• Email
• Follow

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

See related articles to this posting

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

1 Replies
531 Views

Similar Articles

12/6/2013 12:00:36 AM
[PageSpeed]

Similar Artilces:

rule to rewrite
Hi everyone! I need some help to configure my rewrite rule for these url : http://www.test.com/start forward to http://www.test.com/action/start.php http://www.test.com/user/delete/1 forward to http://www.test.com/action/user.php?action=delete&id=1 http://www.test.com/acao/community/post/3 forward to http://www.test.com/action/community.php?action=post&id=3 And i need this too: http://fred.test.com forward to http://www.test.com/action/user.php?action=profile&login=fred Anyone can help me with this ? Thnaks to all ! Bye ! On 11 Oct, 14:02, fredBH <fre...@gmail.com> wrote: > Hi everyone! > > I need some help to configure my rewrite rule for these url : > > http://www.test.com/start forward tohttp://www.test.com/action/start.phphttp://www.test.com/user/delete/1 forward tohttp://www.test.com/action/user.php?action=delete&id=1http://www.test.com/acao/community/post/3 forward tohttp://www.test.com/action/community.php?action=post&id=3 > > And i need this too:http://fred.test.com forward to http://www.test.com/action/user.php?action=profile&login=fred > > Anyone can help me with this ? > > Thnaks to all ! >

Deleting rule by pref?
With iproute2 on Linux, is it possible to delete a rule by pref number? [root@gw2 iproute2]# ip ru ls 0: from all lookup local 32764: from 10.2.0.102 to 10.1.0.104 lookup t2 32765: from 10.2.0.0/16 to 10.1.0.0/16 lookup main prohibit 32766: from all lookup main 32767: from all lookup 253 [root@gw2 iproute2]# ip ru del prio 32764 RTNETLINK answers: No such process Or do I have to specify the entire rule?

Validation rule #5
I am trying to create a validation rule in the DOB field of a table to ensure the person is 16 years of age or older, can any one help with this? Thanks Try: >= DateAdd("yyyy", -16, Date()) -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Ant" <ant.snell@virgin.net> wrote in message news:QUNQc.455$H5.33@newsfe3-gui.ntli.net... > I am trying to create a validation rule in the DOB field of a table to > ensure the person...; news:QUNQc.455$H5.33@newsfe3-gui.ntli.net... > > I am trying to create a validation rule in the DOB field of a table to > > ensure the person is 16 years of age or older, can any one help with this? > >

Choose or Rule with Data Dictionary
Hello Folks, I have noticed a difference in the optimizer choices between 10g and 9.2 for : select * from all_tab_columns - choose in 9.2.0.6 select * from all_tab_columns - hint in 10.2.0.1.0 Any reason as to why they are different. I'm having an issue with a view that joins to all_tab_columns. I have specified the all_rows hint to fix the preformance problem but I'm curious as to why they are different. The big question here is: did you analyze the DD? Used to be a big no-no, is atucally supported in 9i onwards. frank.van.bortel@gmail.com wrote: > The big question here i

footnote splitter rule

Safety of local-loopback access rule
Hello, I'm using Cygwin's Xwindows. When I launch applications that connect to the windowing system, the Kerio Personal Firewall 2.1.5 catches it. I launched a few Xwindows applications to characterize the accesses: Local Remote ------------- :1120 127.0.0.1:1034 :1122 127.0.0.1:1034 :1123 127.0.0.1:1023 :1124 127.0.0.1:1034 :1125 127.0.0.1:1125 Both TCP and UDP (outgoing) is required for most of the applications tried. I created a single rule for any application and any port to allow access for the plurality of applications: Local_Loopback_for_Xwin ----------------------- * Protocol: TCP and UDP * Direction: Outgoing * Local endpoint: Any port, any application - Different applications use different ports e.g. 1120, 1122, 1123, 1124, 1125 * Remote endpoint: 127.0.0.1, any port - Different applications use different ports e.g. 1034, 1034, 1023, 1034, 1125 * Always permit Since it's a local connection, is it safe to have an open-ended port specification and open-ended application specification? The safer alternative is to specify exactly which application the rule applies

Making a "catch all" rule
Hello, I'd like to make the following thing: I have many domains like sub.topdomain.com, and for each of these domains a particular address which can be sales@sub.topdomain.com. I use the virtusertable to redirect all these address in a central place. But I'd like to be able to manage the remaing sales@*.topdomain.com I've try this with Local_check_rcpt: LOCAL_RULESETS SLocal_check_rcpt R $*$: $>canonify$1 R $* sales < @$+ . topdomain.com > $*$: bob@topdomain.com But it doesn't work like expected. If I test this rule with sendmail -bt, it works... to > redirect all these address in a central place. But I'd like to be able > to manage the remaing sales@*.topdomain.com > > I've try this with Local_check_rcpt: > LOCAL_RULESETS > SLocal_check_rcpt > R $*$: $>canonify$1 > R $* sales < @$+ . topdomain.com > $*$: bob@topdomain.com > > But it doesn't work like expected. If I test this rule with > sendmail -bt, it works fine, but if I test the whole check_rcpt ruleset, > I see that even if Local_check_rcpt returns the expected result, finally > the check_rcpt doesn'

Unable to change Norton firewall rule ....
I've been trying to change a rule in my Symantec Norton Personal firewall. I open the Norton Internet Security window, and click "Personal Firewall." In the pane that opens, I click "Configure." When this happens, a dialog box opens, reading (in part) as follows. "Symantec Integrator has encountered a problem and needs to close. We are sorry for the invonvenience." Then, the Internet Security window closes. Any helpful advice would be greatly appreciated! Charles Varner HHI, SC

Firewall With Best Rule Organization Metaphor?
Which firewalls have the best rule organization metaphor in their GUI for constructing and maintaining rules? I'm interested in products that can scale their rulesets to hundreds of rules and dozens of different networks without becoming too difficult to read and maintain. To be honest I have never met a firewall I really liked, and I have used Checkpoint Firewall-1, Microsoft ISA Server, and a handful of lesser known firewalls. The shortcoming of all of them in a non-trivial network is that once a ruleset becomes sufficiently large it becomes very very hard to read through... inoperative. Specific rules that you establish for a host or network segment can likewise render a broader rule stated later inoperative. All of this is made worse by software GUI interfaces in most firewalls that use a purely linear organization scheme for rules. This makes reading the ruleset like reading through a 500 line program that has no indenting or formatting structures for ease of reading or grouping of related items. Is there a product whose user interface for ruleset organization uses a metaphor that scales to a larger number of rules? In my opinion Checkpoint

ip rule with fwmark not working in 2.6.31?
Hi, I have a setup where I do policy routing based on a mangle-table with ip rule fwmark. This worked until 2.6.30 with 2.6.31 ip rule does work eg with a source address ip rule from 1.2.3.4 lookup 1 but not with ip rule from all fwmark 0x01 lookup 1 The problem is, that the answer packets are dropped. I use CONNMARK in the iptables rules. Anybody has an idea if there was a change from 2.6.30 to 2.6.31? Konstantin -- Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de Altersheimerstr. 1, 81545 Muenchen, Germany. Tel +49 89 69370185 ---------------------------------------------------------------------------- "Captain, this ship will not survive the forming of the cosmos." B'Elana Torres Hello, Konstantinos Agouros a �crit : > > I have a setup where I do policy routing based on a mangle-table with > ip rule fwmark. This worked until 2.6.30 with 2.6.31 ip rule does work > eg with a source address > ip rule from 1.2.3.4 lookup 1 > but not with > ip rule from all fwmark 0x01 lookup 1 > The problem is, that the answer packets are dropped. I use CONNMARK in the > iptables rules. Anybody