Hey! Sign in to get help with your study questionsNew here? Join for free to post

MATLAB help - Approximating areas below curves

    • 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: 20
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
Write a reply… Reply
Submit reply


Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. Oops, you need to agree to our Ts&Cs to register
  2. Slide to join now Processing…

Updated: October 14, 2016
How many mugs of tea do you drink a day?
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
Study resources

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.