How do i get this script to work correctly

조회 수: 3 (최근 30일)
ky win
ky win 2015년 6월 3일
댓글: ky win 2015년 6월 3일
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"

채택된 답변

Star Strider
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.
  댓글 수: 1
ky win
ky win 2015년 6월 3일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by