MATLAB: I keep getting the message: Unbalanced or unexpected parenthesis or bracket. How to fix it? I’m trying to solve for the maximum and minimum with a function and it’s constraint.

absolute maximum minimum

syms x y lam
f = 2*x^4-x^2+3*y^2
g = x^2+y^2+3*y-9
fx = diff(f,x)
fy = diff(f,y)
gx = diff(g,x)
gy = diff(g,y)
[alam ax ay] = solve( fx-lam*gx, fy-lam*gy)
[bx by] = solve( gx,gy )
T = [ ax ay subs(g,{x y},{ax ay}) subs(f,{x y}, {ax ay })({bx by}) subs(g,{x y},{
bx by}) subs(f,{x y}{bx by})]
double(T)
double(T([1,2,3,4,7,8],[1,2,3,5]))

Best Answer

T = [ ax ay subs(g,{x y},{ax ay}) subs(f,{x y}, {ax ay })({bx by}) ...
subs(g,{x y},{bx by}) subs(f,{x y}{bx by})]
This part is not valid MATLAB syntax.
subs(f,{x y}, {ax ay })({bx by})
I suspect what you want it to make T a two row matrix where the first consists of ax and ay and the results of substituting those into g and f and the second consists of bx and by and the results of substituting those into g and f. If that's the case:
T = [ ax, ay, subs(g, {x y}, {ax ay}), subs(f, {x y}, {ax ay}); ...
bx, by, subs(g, {x y}, {bx by}), subs(f, {x y}, {bx by})]
If that's not what you want explain in words, not code, what you expect / want that section of code to do. Once we know your goal we may be able to help you express that in code.
Related Question