- #1

- 4

- 0

## Homework Statement

Write a script file to integrate the function f(x)=x^3+tan(x)+C using the trapezium rule.Calculate the integral between the end points x=2 and x=4 with strip size 0.1.Calculate the integral for range of values from 1 to 3 in steps of 0.1.plot the integral obtained for different values of C?

## Homework Equations

I wrote the code and it is calculating the correct integrals but it is not plotting the integrals obtained for different values of C .can u please help me to modify my code so that it plots :)

## The Attempt at a Solution

This is my code that I have been working on:

% What are the integration limits?

clc

a = 2;

b =4;

% What is the integration step size?

dx = 0.1;

% An array containing the x points.

x = [a:dx:b];

% What is the function to integrate?

C=1:0.1:3;

C;

y =x.^3+tan(x)+C;

% The number of points

N = length(y);

%initialise the area variable

sum_y = 0;

%sum the interior elements of the y array

%note how the loop starts at 2 and stops at N-1

for I = 2:N-1

sum_y = sum_y + y(I);

area = dx*((y(1) + y(N))/2 + sum_y)

plot(area,C)

end

Thank you for your help:)