"Not enough input arguments" error when integrating a function

1 次查看(过去 30 天)
Hi guys,
I am trying to numerically integrate a function and keep receiving the error "Not enough input arguments."
My code:
integral(fun,0,1)
while fun.m reads:
function [ y ] = fun( x ) y = x*2 + 1; end
What am I missing here? Thanks in advance!

回答(2 个)

Kye Taylor
Kye Taylor 2013-3-19
You need to use a function handle... try
integral(@fun,0,1)

Fabian
Fabian 2013-3-19
thank you, it works now
I have another question: I run a script which defines a bunch of variables which are visible in the base workspace (right?). Then, the script runs the function which is supposed to use these variables. is there a quick way to make a function "see" the variables from my base workspace or do I have to define all variables as global in both the function and the script?
cheers
  1 个评论
Kye Taylor
Kye Taylor 2013-3-19
Yeah... pass those variables as input to the function (best practice).
Also, please accept answers that you find helpful. (My first one.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by