Why does my code say too many input arguments?

function [ rts, info ] = cubicxxxx( C )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%C = [1 3 4 5]%example of vector
x0=1;
f=@ (x) C(1,1)*x.^3+C(1,2)*x.^2+C(1,3)*x+C(1,4);% cubic function
g=@ (x) C(1,1)*3*x.^2+C(1,2)*2*x+C(1,3);% derivative of cubic function
f(x0);
g(x0);
b=f(x0)-0;
while b<10^-6
y =x0-((f(x0))/(g(x0)));
x0=y;
b=f(x0)-0;
end
display(x0)
end

Réponses (1)

James Tursa
James Tursa le 9 Fév 2017
Modifié(e) : James Tursa le 9 Fév 2017
How are you calling this function? E.g.,
>> cubicxxxx(1:4) % <-- one input vector
x0 =
1
>> cubicxxxx(2:5) % <-- one input vector
x0 =
1
>> cubicxxxx(2:5,8) % <-- two inputs
??? Error using ==> cubicxxxx
Too many input arguments.
>> cubicxxxx(1,2,3,4) % <-- four inputs
??? Error using ==> cubicxxxx
Too many input arguments.
>> cubicxxxx([1,2,3,4]) % <-- one input vector
x0 =
1

Catégories

En savoir plus sur Functions dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by