integrating input variable function
Show older comments
how can i input a user defined variable/ quadratic equation and integrate it?
what i am trying to do is ask user for the equation in then integrate it, (no limit) and give the ans
Accepted Answer
More Answers (1)
mohammad reza
on 12 Jul 2016
0 votes
1 Comment
Star Strider
on 12 Jul 2016
To create a funciton handle, add str2func and sprintf calls:
prompt = {'x^2 Coefficient', 'x Coefficient', 'Constant'};
default_ans = {'0','0','0'};
dlg_title = 'Quadratic Equation';
num_lines = 1;
valc = inputdlg(prompt, dlg_title, num_lines, default_ans);
vals = cell2mat(valc);
valn = str2num(vals);
qcf = valn(1:3);
qint = polyint(qcf.');
intquad_fcn = str2func(sprintf('@(x) %f.*x.^3 + %f.*x.^2 + %f.*x + %f', qint))
intquad_fcn =
@(x)0.333333.*x.^3+1.000000.*x.^2+3.000000.*x+0.000000
It exists as the function in the code, so adding one line to test it:
intquad_val = intquad_fcn(5) % Test Line (Delete Later)
intquad_val =
81.6666e+000
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!