How to make a function file that displays a polynomial and accepts a specific command?

1 visualización (últimos 30 días)
function lou(a,b,c)
fprintf('%dx^2 + %dx + %d =0 \n',a,b,c)
end
this is my code right now. how do i modify my code to make the command lou([a b c]) work?

Respuesta aceptada

Rik
Rik el 15 de Abr. de 2022
Why do you want to call your function like that? lou(a, b, c) will already work.
Anyway:
function lou(a,b,c)
if nargin==1,c=a(3);b=a(2);a=a(1);end
fprintf('%dx^2 + %dx + %d =0 \n',a,b,c)
end

Más respuestas (1)

KSSV
KSSV el 15 de Abr. de 2022
val = lou(1,2,3,.2)
1x^2 + 2x + 3 =0
val = 3.4400
function val = lou(a,b,c,x)
fprintf('%dx^2 + %dx + %d =0 \n',a,b,c)
val = a*x^2+b*x+c ;
end

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by