0

I am trying to integrate a function F which is defined as:

function F        
    x = -3:0.1:3;
    F = zeros(1, length(x));
    for i = 1:length(x)
        if (1.4<= x(i)) && (x(i) <= 1.6)
            F(i) = x(i).^2;
        else
            F(i) = 2;
        end
    end 
end

but the integral function gives me an error saying that there are too many arguments. I think the problem that the function is defined as a points?

Wolfie
  • 27,562
  • 7
  • 28
  • 55
Imran
  • 23
  • 2
  • 4
    Please, for the shake of all of us, indent that code properly. Also, show us the code that errors. You are esentially not understanding how to call integral. A function is something of the form `f(x)`, your F has not inputs. You should not define `x`, else `F` is an array, not a function. – Ander Biguri May 31 '17 at 14:43
  • The problem is with the line where you call the `integral` function, show us *that* line of your code too! – Wolfie May 31 '17 at 14:50
  • I call the int function like integral(F,0,1) and i get the error Error using F Too many output arguments. as you said i think my function F is an array,if that the problem so how could I define F as a function? – Imran May 31 '17 at 15:08

1 Answers1

0

The problem with your function, is that integral has no way to pass the arguments you supply to your function F. The function doesn't know that it can just pull certain elements from the vector you created. If you rewrite your function such that for an input (or x value), the output of F is returned, then integral will work as you need given two values to integrate between.

Drofdarb
  • 159
  • 1
  • 9