Converting a string to a double when it includes symbols (in nonlinear inequality solving)
Show older comments
First of all, the nonlinear inequality constraints page is here: Nonlinear inequality constraints. Please go have a look at defining c in Step 2 to understand my problem properly.
In Step 2, one must define a list of constraints called "c". I intend to be solving nonlinear inequalities in a loop, and am therefore getting the computer to write the constraint list for me as a string. Say my constraint list (outside of confun.m) is
constraint = '[1.5 + x(1)*x(2) - x(1) - x(2);-x(1)*x(2) - 10]'
so that class(constraint) = char . I attempt to pass it to confun.m as c = constraint, it tells me it requires it to be of type double. This is fair. When I attempt to pass it as c = str2num(constraint), it makes c = [], because presumably it cannot understand the x's. And c = str2double(constraint) produces c = NaN. I have also tried various combinations of things using syms and eval, to no end. How do I do this in the right way?
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Operations on Strings 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!