How do i get this script to work correctly
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 3 Giu 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!