Join TSR now and get all your revision questions answeredSign up now

MATLAB help - Approximating areas below curves Watch

    • Thread Starter

    The below code is for Q1, does anybody know how I could possible edit it so that it could apply to Q2?

    " clear all;
    format long;
    n = 80;
    a = 0; b = 1;
    h = (b-a)/n;
    x = linspace(a,b,(n+1));
    integral = h.*sum(exp(x(1:n))) "

    Name:  matlab2.jpg
Views: 21
Size:  20.1 KB This is for e^x between 0 and 1


    If you look at x(1:n) from your code from Q1 in MATLAB (in your console simply enter x(1:n) after running your code) you will see that it it stores values for steps 1-80, however your linspace function is a 1x81 double.
    This is a clue how to solve Q2. You need shift your initial starting and final steps forward one step higher (as denoted by x_i_+_1) so it runs from 2-81.

    If you get it working and want to check if you're getting the correct value, you can add the following and if your value for Q3 is the same to 4 S.F. you're dandy.

    fun = @(x) exp(x); % Setup Function for Integration

    q = integral(fun,0,1) % Integrate and print function to console
Is GoT overrated?
Useful resources

Make your revision easier


Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here


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.