필터 지우기
필터 지우기

input equation from user

조회 수: 8 (최근 30일)
Saumya
Saumya 2014년 4월 25일
답변: Mohammed Alrajeb 2019년 8월 9일
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.

채택된 답변

Jos (10584)
Jos (10584) 2014년 4월 25일
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
Saumya
Saumya 2014년 4월 29일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Manjeet Singh
Manjeet Singh 2016년 4월 5일
편집: Stephen23 2016년 6월 24일
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
Sourin Dey
Sourin Dey 2016년 6월 24일
Can you kindly show me the way to read the coefficients from the input equation? (The equation will be taken using input function)

댓글을 달려면 로그인하십시오.


Mohammed Alrajeb
Mohammed Alrajeb 2019년 8월 9일
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?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by