Dont understand the code
1 view (last 30 days)
Show older comments
my code is:
*function [ y ] = integral(n0)
y=0;
for n=n0:-1:20
y=1/10*(1/n-y);
end
z = quad(@(x)fun1_6(x ,20) ,0 ,1 ,1.e-10);
fprintf('%e %e %e\n',y,z,abs(y-z))*
I dont understand the line "z = quad(@(x)fun1_6(x ,20) ,0 ,1 ,1.e-10)" can any one explain to me?
0 Comments
Answers (1)
Star Strider
on 28 Jan 2015
Edited: Star Strider
on 28 Jan 2015
That line integrates ‘fun1_6’, that takes two arguments, x and second argument that is assigned the value of 20 here, and using the quad function, numerically integrates it over x only, from 0 to 1, with a tolerance of 1e-10, and assigns it to the variable z.
2 Comments
Star Strider
on 28 Jan 2015
The ‘@(x)’ is a function handle, in this instance to an anonymous function created so that ‘fun1_6’ is only passed a value for x.
In the function handle documentation (that I linked to here), see specifically Example 2 — Constructing a Handle to an Anonymous Function.
The documentation explains it much better than I can.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!