You are Here: Home >< Maths

# MATLAB help - Approximating areas below curves Watch

1. 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))) "

This is for e^x between 0 and 1
2. Hi,

If you look at 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 ) so it runs from 2-81.
Spoiler:
Show

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

Updated: October 14, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Today on TSR

### Stuck for things to do this summer?

Come and get some inspiration.

Poll
Useful resources

### Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

### How to use LaTex

Writing equations the easy way

### Study habits of A* students

Top tips from students who have already aced their exams