Borrar filtros
Borrar filtros

I am trying to get my answer to Display but it wont let me

4 visualizaciones (últimos 30 días)
Bastian
Bastian el 12 de Dic. de 2023
Respondida: Voss el 12 de Dic. de 2023
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
disp('the roots will be',(x))
says error below-
Incorrect number or types of inputs or outputs for function extractCreationTimeDigits.
Error in sym/disp (line 16)
useDigits = extractCreationTimeDigits(X);
Error in Workshop_5_Excercise_3_Pt_1 (line 4)
disp('the roots will be',(x))
>>
  1 comentario
Stephen23
Stephen23 el 12 de Dic. de 2023
DISP has only one input argument.
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
disp(x)

Iniciar sesión para comentar.

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 12 de Dic. de 2023
The function disp accepts only 1 input argument.
If you want to display the roots and the text in the same line, you will have to create a string before using disp, see this example for reference - https://in.mathworks.com/help/matlab/ref/disp.html#btnoykw-1
If you want to display them seperately, you can call disp() twice like this -
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x)
x = 
disp('the roots will be')
the roots will be
disp(x)

Más respuestas (5)

Christopher McCausland
Christopher McCausland el 12 de Dic. de 2023
Hi Bastian,
Try replacing
disp('the roots will be',(x))
with
fprintf('the roots will be %d. \n',x)
This should correct the string formating and print as desired.
Christopher

Star Strider
Star Strider el 12 de Dic. de 2023
Another option —
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
disp(["the roots will be ",string(x.')])
"the roots will be " "-3" "1" "2"
Note the use of string arrays and the simple transpose, .' operator.
.

Voss
Voss el 12 de Dic. de 2023
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
str = sprintf('%s ',x);
str(end) = [];
fprintf('the roots will be [%s]\n',str)
the roots will be [-3 1 2]

Voss
Voss el 12 de Dic. de 2023
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
fprintf('the roots will be [%s]\n',strjoin(string(x)))
the roots will be [-3 1 2]

Voss
Voss el 12 de Dic. de 2023
syms f(x)
f(x) = (x^3) - (7*x) + 6;
x=solve(f(x)==0,x);
fprintf('the roots will be [%s]\n',join(string(x)))
the roots will be [-3 1 2]

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by