How to get a function from user without knowing its symbols
Show older comments
Hi everyone I want to create a general program which users insert their desired function and my program do a mathematic operation (like integration) on it and gives the answer. The problem is that i don't know what is the function and its variable, it might be a function of x, or y or z, or there might be some constant variables. For example users may want to solve an integration of A1 + (x/L)*A2, respect to "x" base on A1, A2 and L. Or they want to solve integral of Ax+by respect to y. The problem is I don't know which character user will use, so that i can define it as symbol. How could I do this?
Accepted Answer
More Answers (1)
Jan
on 24 Nov 2020
0 votes
See how e.g. fzero and ode45 solves this problem. Here the function has 1 oder 2 variables which must be provided in a specific order. Constants are delivered to the function using anonymous functions. How the variables are called internally does not matter. The user simply provides the function handle and only the order of variables matter.
2 Comments
Soheil Khoshboo
on 24 Nov 2020
Edited: Soheil Khoshboo
on 24 Nov 2020
Jan
on 25 Nov 2020
You finde the explanations in the documentation:
doc fzero
doc ode45
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!