Solving Equations

Michael Bar, San Francisco State University
Table of Contents
clear %Clearing memory
close all

Solving a system of two non-linear equations

Consider two non-linear equations:
syms x y %Declaring symbolic variables
eq1 = y==exp(x)
eq1 = 
eq2 = y==1/x
eq2 = 
[x_sol, y_sol] = vpasolve([eq1,eq2], [x,y], [1,1]) %The last argument is initial guess
x_sol = 
0.56714329040978387299996866221036
y_sol = 
1.7632228343518967102252017769517

Plotting the equations near solution

fplot([exp(x), 1/x],[0.1,2], 'LineWidth',2)
hold on
plot(x_sol,y_sol,'r.','MarkerSize',25) %Adding the solution point
hold off
title('Solution to [y = exp(x), y = 1/x]')
xlabel('x')
ylabel('y', "Rotation",0)
legend('y = exp(x)','y = 1/x', 'Location', 'best')
grid on
grid minor