Trying to Create a Riemann Sum function from scratch, keep getting function error.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So i have to create a riemannsum calculator function, its been a little bit since ive used MatLab, but this seems right i just dont understand why i keep getting this error.
function [ Result ] = RiemannSum(Fun,a,b) %This function will calculate the riemann sum of a function defined from an %interval from a to b. This will be done using 10 subintervals.
dx=(b-a)/10;
XS=(a+(dx/2):dx:b-(dx/2));
Result=sum((feval(Fun,XS)).*dx);
The error i get is : RiemannSum(2*x,1,10) Undefined function or variable 'x'.
Even if i set x=XS it doesnt fix the error, im really stuck here.
Or when i tinker around and first run x=[] ill get this error instead.
Error using feval Argument must contain a string or function_handle.
Error in RiemannSum (line 6) Result=sum((feval(Fun,XS))*dx); end
0 Kommentare
Akzeptierte Antwort
Rick Rosson
am 1 Sep. 2014
Please type the following at the MATLAB Command Prompt:
F = @(x) 2*x;
R = RiemannSum(F,1,10);
7 Kommentare
Weitere Antworten (1)
Amar
am 1 Sep. 2014
1 Kommentar
Rick Rosson
am 1 Sep. 2014
Please do not post answers to your own question. Instead, post a comment to your question or to an answer, or edit your question.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!