How to get functions out of inputdlg
1 次查看(过去 30 天)
显示 更早的评论
questions = {'Enter a function','Enter a lower limit','Enter an upper limit'};
prompt = inputdlg(questions)
equation = str2num(prompt{1})
lower_limit = str2num(prompt{2})
upper_limit = str2num(prompt{3})
P=int(sym('equation'),lower_limit,upper_limit)
Hello everyone. My question is how do I keep the inputted equation (such as x.^2) as itself, instead of it changing to x. When I run the program below (you should be able to copy and paste it if you want to run it) the inputted function gets changed to x. Many thanks.
0 个评论
采纳的回答
Star Strider
2020-4-6
questions = {'Enter a function of ‘x’','Enter a lower limit','Enter an upper limit'};
prompt = inputdlg(questions)
equation = str2func(['@(x) ',vectorize(prompt{1})])
lower_limit = str2num(prompt{2})
upper_limit = str2num(prompt{3})
P=integral(equation,lower_limit,upper_limit)
Experiment to get different results.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!