Author Topic: How to ask a function from user and save it  (Read 769 times)

Offline masael_gb

  • Newbie
  • *
  • Posts: 1
  • Matlab Forum
    • View Profile
How to ask a function from user and save it
« on: December 30, 2010, 02:47:49 PM »
I need a code to use it in m.file. It is about to ask a function from user and save it.
What I did was so but the answer was :" ans = sin(x)"

k.name = input('Enter the function')
fcn = @(x) k.name;
fcn(2)

when I run it and give it sin(x) the answer is "ans =  sin(x)". What is the problem? :o
In fact the function I need is a function of two variables.
Another question:
I want to declare dy=cos(x)+sin(x)y when y if a function of x. Then I want matlab to calculate d2y like this:
d2y=-sin(x)+cos(x)*y+(cos(x)+sin(xy))*sin(x)
How can I do it? ;)
« Last Edit: December 30, 2010, 02:55:25 PM by masael_gb »

Matlab and SimuLink Development Forum

How to ask a function from user and save it
« on: December 30, 2010, 02:47:49 PM »