How do i get this script to work correctly

2 views (last 30 days)
Given the function y=sin(x), for n=10,100,1000,10000 estimate: 1. the area under the curve in the interval [0,pi/2]. Compute for each n, the US, LS from the estimation Max error of each n Make a table with the values of n and max errors, or between delta and max errors.
My script thus far is: f=inline('sin(x)')
a=0 b=pi/2 n=[10 100 1000 10000]
deltaX=(b-a)./n;
xu=linspace(a,b-deltaX,n);
xl=linspace(a+deltaX,b,n);
US=deltaX.*sum(f(xu)); LS=deltaX.*sum(f(xl));
Estimate=(US+LS)./2 error=(US-LS)./2
But i get this "error: C2L1P2.m: product: nonconformant arguments (op1 is 1x4, op2 is 1x10) error: called from: error: /home/oo/C2L1P2.m at line 13, column 3"

Accepted Answer

Star Strider
Star Strider on 3 Jun 2015
First, you do not need the inline call (that is incorrect anyway because you do not specify that the argument to it should be ‘x’). So just use a direct call to sin(x).
Unless this is a homework assignment and you are restricted in the functions you can use (that we need to know if you want our hints), I would use the trapz or cumtrapz function if you have to calculate the vector first, or the integral function if you can use the functions directly.
  1 Comment
ky win
ky win on 3 Jun 2015
Thank you, this is a homework problem, and im pretty sure they do not want me using the easy methods until after they show it to us.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!