Not enough input errror
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
function [ x ] = cubicroots( a, b, c, d )
% find the real roots of the cubic equation ax^3 + bx^2 + cx + d
% input parameters
% a = real coefficient of cubic equation
% b = real coefficient of cubic equation
% c = real coefficient of cubic equation
% d = real coefficient of cubic equation
% output parameter
% x = 1 x 3 vector containing the 3 roots of the cubic equation
D=18*a*b*c*d-4*b^3*d+b^2*c^2-4*a*c^3-27*a^2*d^2;
D0=b^2-3*a*c;
D1=2*b^3-9*a*b*c+27*a^2*d;
k=D1^2-4*D0^3;
u1=1;
u2=(-1+i*sqrt(3))/2;
u3=(-1-i*sqrt(3))/2;
C=((D1^2+sqrt(k))/2)^(1/3);
if D<0
x(1)=(-1/3*a)*(b+u1*C+(D0/u1*C));
x(2)=NaN;
x(3)=NaN;
else
x(1)=(-1/3*a)*(b+u1*C+(D0/u1*C));
x(2)=(-1/3*a)*(b+u2*C+(D0/u2*C));
x(3)=(-1/3*a)*(b+u3*C+(D0/u3*C));
end
error line 16 "not enough input arguments"
Antworten (1)
Geoff Hayes
am 2 Jun. 2016
laurae1234 - how are you calling this function? Given the signature,
function [ x ] = cubicroots( a, b, c, d )
you need to provide four inputs. So calling this function as
>> cubicroots
will generate the error
Error using cubicroots (line xx)
Not enough input arguments.
You need to pass in the coefficients of the cubic equation
ax^3 + bx^2 + cx + d
If there is none, then pass in zero. For example, if the equation is
x^3 + 2b^2 + 4
then you would call this function as
>> cubicroots(1,2,0,4)
The above "works" in that it gives an answer, but I don't think it gives an accurate root of the cubic equation...
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!