Borrar filtros
Borrar filtros

input equation from user

8 visualizaciones (últimos 30 días)
Saumya
Saumya el 25 de Abr. de 2014
Respondida: Mohammed Alrajeb el 9 de Ag. de 2019
Hi, I am a new user for MATLAB and I have R2010a version. I want to write a program where user should be able to enter euqation as input. e.g. : 5x^2 + 2x =8. And once the equation is fed in, I want to find out value of the equation for a perticular x value.
Please help.

Respuesta aceptada

Jos (10584)
Jos (10584) el 25 de Abr. de 2014
str = input('Give an equation in x: ','s') ;
% the user types in, for instance 2*x^2-3*x+4
x = input('Type in a value of x: ') ;
% the user types in, for instance, 2
f = inline(str,'x') ;
y = feval(f,x) ;
disp(['"' str '", for x = ' num2str(x) ', equals ' num2str(y)]) ;
This will error when the string cannot be converted to an inline function or when the function cannot be evaluated for the value entered by the user.
  1 comentario
Saumya
Saumya el 29 de Abr. de 2014
Thank you Jos,
It was really helpful.
Now going one step ahead, how can I do the same for a function with 2 variables say x and y.

Iniciar sesión para comentar.

Más respuestas (2)

Manjeet Singh
Manjeet Singh el 5 de Abr. de 2016
Editada: Stephen23 el 24 de Jun. de 2016
str = input('Give an equation in x and y: ','s'); % the user types equation in form of x and y
f = inline(str,'x','y') % This gives function in form of f(x,y) $ both value of x and y can be put like f(2,3)
  1 comentario
Sourin Dey
Sourin Dey el 24 de Jun. de 2016
Can you kindly show me the way to read the coefficients from the input equation? (The equation will be taken using input function)

Iniciar sesión para comentar.


Mohammed Alrajeb
Mohammed Alrajeb el 9 de Ag. de 2019
hi every one
i need to your help
i need to enter 4 input (decimal number) and convert to binary number 32bit how can do that?

Categorías

Más información sobre Logical 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