how to set the domain of a function

Hello please how do I set the domain for my function :
f(x1,x2)= -9*x(1) - 10*x(2) + 10*(-log(100-x(1)-x(2))-log(x(1))-log(x(2))-log(50-x(1)+x(2)));
X{(x1,x2)|x1>0,x2>0,x1+x2<100,x1-x2<50}
thanks

 Accepted Answer

syms x [1 2]
f(x) = piecewise(x(1)>0 & x(2)>0 & x(1)+x(2) <100 & x(1)-x(2)<50, -9*x(1) - 10*x(2) + 10*(-log(100-x(1)-x(2))-log(x(1))-log(x(2))-log(50-x(1)+x(2))), NaN)
f(x1, x2) = 
fsurf(f, [-5 105 -5 105] ); xlim([-5 105]); ylim([-5 105])

4 Comments

Thank you very much it worked!
Just one more doubt, so that I can understand what I did better
syms x[1 2] keeps giving me this error:
Error using syms (line 293)
Invalid variable name.
Error in text_line (line 3)
syms x[1 2];
so I did: syms x1 x2;
x=[1 2]
and it worked, just wondering if it makes any difference expecially since because of the function:
f(x1,x2)=....
syms x [1 2]
Notice the space.
However I see now that you are using an older release. You would need
x = sym('x', [1 2]);
Okay, thank you very much!!

Sign in to comment.

More Answers (0)

Products

Release

R2015a

Community Treasure Hunt

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

Start Hunting!