Clear Filters
Clear Filters

how to extract coefficients of a symbolic to plot Contour plot, for that equation over a range of max & min values?

1 view (last 30 days)
I've 2 quadratic equations:
g1(x) = A1*x1^2 + B1*x1*x2 + C1*x2^2 + D1*x1 + E1*x2 + F1
g2(x) = A2*x1^2 + B2*x1*x2 + C2*x2^2 + D2*x1 + E2*x2 + F2
where g(x) = g1(x) - g2(x)
I have to plot the contour plot at zeroth level for g(x).
here's the way I'm doing but not sure how to extract the coefficients value.
%%%found g1 g2 & g
x1= -10:0.5:10 ;x2=-10:0.5:10;
x = subs(g);
[num idx] = max(x(:));
[x1max x2max] = ind2sub(size(x),idx)
[num idx] = min(x(:));
[x1min x2min] = ind2sub(size(x),idx);
[z1 z2] = meshgrid(x1min:0.5:x2max,x2min:0.5:x2max);
Z = a*x1.^2 + b*x1.*x2 + c*x2.^2 + d*x1 + e*x2 + f;
contour(z1,z2,Z,[0 0]);
how can I automatically pass values of a,b,c,d,e & f from g to Z?
the values are like this..
g1 =
- 0.041*x1^2 + 1.2*x1 - 0.041*x2^2 - 15.0
- 0.041*x1^2 - 0.041*x2^2 + 1.2*x2 - 15.0
g2 =
- 0.029*x1^2 + 1.1*x1 - 0.029*x2^2 - 18.0
- 0.029*x1^2 - 0.029*x2^2 + 1.1*x2 - 18.0
g =
- 0.012*x1^2 + 0.1*x1 - 0.012*x2^2 + 3.0
- 0.012*x1^2 - 0.012*x2^2 + 0.1*x2 + 3.0
Really appreciate your help.

Answers (2)

Walter Roberson
Walter Roberson on 2 Dec 2012
Use coeffs() for this situation.
However, your g1(x) and g2(x) are not functions in x, except degenerately: they do not involve x in their expression, only x1 and x2.

zaxven
zaxven on 2 Dec 2012
Edited: zaxven on 5 Dec 2012
if i do coeff(g) ===> error :: Undefined function 'coeff' for input arguments of type 'sym'.
and for coeffs(g)
===> ans =
matrix([[- 0.012*x1^2 + 0.1*x1 - 0.012*x2^2 + 3.0], [- 0.012*x1^2 - 0.012*x2^2 + 0.1*x2 + 3.0]])
really appreciate your help.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!