Extract numerical value from gradient
1 view (last 30 days)
Show older comments
Hi all,
I'm working with a third party optimizer (GPOPS) that interacts with MATLAB. As I need to calculate the root of a 4th order polynomial, I'm using the "roots"-function to solve for these:
a = 1;
b = 2*(UC(i));
c = (((UC(i)).^2) + ((UT(i)).^2));
d = 0;
e = -1;
v_i_norm_roots(:,i) = roots([a b c d e]);
This works at first when the problem is initialized, because at this point the values for UC and UT are doubles. However, after this the optimizer starts the iterative optimization. At this point, UC and UT are not doubles anymore, but a gradient of this value is sent to the "roots"-function. Because of this I cannot get the "roots"-function to work as I get the error:
Error using zeros
CLASSNAME input must be a valid numeric or logical
class name.
Error in roots (line 32)
r = zeros(0,1,class(c));
Error in vinorm_analytical_testwithroots (line 65)
v_i_norm_roots(:,i) = roots([a b c d e]);
When the gradient starts being sent to the roots function b and c equal the following:
b
gradient value b.x =
0.1100
gradient derivative(s) b.dx =
(1,244) 0.1100
(1,325) 0.0019
(1,649) -0.0019
(1,890) -4.2319
(1,1050) 0.0019
c
gradient value c.x =
0.0030
gradient derivative(s) c.dx =
(1,244) 0.0061
(1,325) -0.0000
(1,649) 0.0000
(1,890) -0.2329
(1,1050) -0.0000
To calculate the roots, I'm only interested in the first value of the gradient; 0.1100 in b and 0.0030 in c. How can I 'extract' this value from a gradient, so I can use it to solve for the root?
Many thanks!!!
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Systems of Nonlinear Equations 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!