Why does my code say too many input arguments?
Show older comments
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
Answers (1)
James Tursa
on 9 Feb 2017
Edited: James Tursa
on 9 Feb 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
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!