how to substitute in simultaneous equations?

10 views (last 30 days)
How to substitute values of the variable in the function (f) and the derivatives of it (df/dx1 and df/dx2),
f(x1,x2) = x1^2 + x1*x2 - 10;
with and without using using symbolic function.

Answers (1)

Imran
Imran on 4 Jan 2023
Hello Medhanand,
I understand that you want to substitute the values of the variables in the given function and in the partial derivatives with and without using a symbolic function.
1. Calculation with symbolic function
The following code demonstrates the process of substitution using symbolic functions:
% Define the symbolic variables
syms f x1 x2;
% Write down the given function
f = x1^2 + x1*x2 - 10;
% Calculate the partial derivative with respect to x1
dfdx1 = diff(f,x1);
% Calculate the partial derivative with respect to x2
dfdx2 = diff(f,x2);
% Substitute the values of the variables in function 'f' and store it in a variable
f_subst = subs(f,{x1,x2},{3,5});
% Substitute the values of the variables in dfdx1 and store it in a variable
dfdx1_subst = subs(dfdx1,{x1,x2},{3,5});
% Substitute the values of the variables in dfdx1 and store it in a variable
dfdx2_subst = subs(dfdx2,{x1,x2},{3,5});
As an example, I have taken the values of 'x1' and 'x2' as 3 and 5 respectively. The 'subs' function is a symbolic function which helps in symbolic substitution.
2. Calculation without symbolic function
If 'x1' and 'x2' are expressed as numeric vectors, the 'gradient' function can used to calculate the partial derivatives. If nothing is explicitly mentioned about the variables, you can use the 'symbderiv' function to calculate partial derivatives.
The following code snippet shows how to substitute the values of the variables without using a symbolic function:
% Define the symbolic variables
syms f x1 x2;
% Write down the given function
f = x1^2 + x1*x2 - 10;
% Just assign values.
x1 = 3;
x2 = 5;
% Calculate the value of the function at the specified point
f_eval = eval(f);
You just need to assign the values to the variables. For calculating the value of function at the specified point, the 'eval' function is used.
I hope this helps.

Community Treasure Hunt

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

Start Hunting!