How do i get this script to work correctly
2 views (last 30 days)
Show older comments
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"
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!