Join TSR now and get all your revision questions answeredSign up now
    • Thread Starter
    Offline

    0
    ReputationRep:
    Hi I'm trying to evaluate the following:

    int((x^3-5.15*x^2+8.55*x-4.5045),x=1..2);

    My current code is:

    restart;

    f:=x->int((x^3-5.15*x^2+8.55*x-4.5045),x=1..2);







    > simp:=proc(func,x0,xn,xi,n)
    > local h,i, summ;
    >
    > h:=xn-x0/n:
    > summ:=int(h/3*(f(x0)+f(xn)+(4*f(xi))+2*f(xi) )):
    > for i from 1 to n-1 by 2 do
    >
    > xi:=x0+i*h:
    >
    > summ:=summ+4*f(xi):
    > od:
    > summ:=h/3*summ;
    > end:
    > for i from 2 to n-2 by 2 do
    >
    > xi:=x0+i*h:
    > summ=summ+2*f(xi):
    > od;
    >
    >
    Error, final value in for loop must be numeric or character

    Im hoping someone could please tell me what the problem is,

    Regards
    • Thread Starter
    Offline

    0
    ReputationRep:
    f:=x->int(evalf(x^3-5.15*n^2+8.55*x-4,5045),x=1..2):
    > simp:=proc(func,x0,xn,n)
    > local summ, h, i,x:
    > x0:=1:
    > xn:=2:
    > n:=8:
    > h:=xn-x0/n:
    > summ:=f(x0)+f(xn):
    >
    > for i from 1 to n-1 by 2 do
    >
    > x[i]:=x0+(i*h):
    > summ:=summ+4*f(x[i]):
    > od:
    >
    > for i from 2 to n-2 by 2 do
    >
    > x[i]:=x0+(i*h):
    > summ:=summ+2*f(x[i]):
    > od:
    >
    > summ:=h/3*summ;
    > end:

    So I've had another go, got this far and now I'm stuck again, how do i get the answer of the integral out?
    Offline

    3
    ReputationRep:
    do you have to use code? (worksheet mode etc)

    why don`t you (if you don`t have to use code) put (as written):

    with(Student[Calculus1]):
    ApproximateInt(your function,x=1..2,method=simpson)

    better still, make the 2nd line begin with:
    ApproximateIntTutor(f(x),x=a..b)
    this gives a graphical display where you can choose which rule to use, and to plot whatever function you wish...
    • Thread Starter
    Offline

    0
    ReputationRep:
    Yes, we have to use a code, cant use maples built in problem solvers.
 
 
 
Poll
Which Fantasy Franchise is the best?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.