Mathematical calculations on input equation

I want to write a program where user should be able to enter equation function of 1 variable. such as sin(t)-2t , but this equation is used in further calculations but i can't make this because the type of it is string. how can i solve this problem or change the type of input data to make mathematical calculations ?

回答(2 个)

What do you mean by function? Is it simply asking for a numerical input? If so,
f=input('enter input num\n')

4 个评论

i meant that the user's func may be sin(t)-2t how can i make calculations on this equation and plot it
Then you can do it using str2func
f = input('Enter the function:\n', 's');
fh = str2func(['@(t)' f]);|
Let's check it.
Enter the function:
2*t + 3*t
>> fh(2)
ans =
10
Hi, I would like user to input function i.e. x^2 + 3*y^3 and then ask user for the value of x and y and get the value of the function for x and y. I have been looking foor an advice on various sites but nothing has worked for me. I have MATLAB R2020b.
Use str2func. See bio lim's comment from November 28, 2016 for an example.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by