How do i get this script to work correctly
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2015-6-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!