Using Matlab Solving Algebraic Equations Analytically
Matlab can be used to solve nonlinear algebraic equations or equation systems. Sometimes only numeric answers are returned. Sometimes, Matlab fails.
Example 1:
>> solve('-x^3 +3*x =0')
ans =
[       0]
[-3^(1/2)]
[ 3^(1/2)]

>> numeric(ans)
ans =
         0
   -1.7321
    1.7321

Or, use the command "roots" for polynomials

>> roots([-1,0,3,0])
ans =
         0
    1.7321
   -1.7321

Example 2:
>> solve('ln(x)+a^2=b')
ans =
exp(-a^2+b)

Example 3:
>> T=solve('ln(T)+a^2=b','T')
T =
exp(-a^2+b)

Example 4: Solving 2 equations simultaneously
>> e1='x1^2 + x2 =10';
>> e2='x1-x2=2';
>> [x1,x2]=solve(e1,e2)
x1 =
[ -4]
[  3]
x2 =
[ -6]
[  1]
You may also use a single command line shown below to get the same answer.
>> [x1,x2]=solve('x1^2+x2=10','x1-x2=2')

Using MATLAB to Solve for Friction Factor Using Colebrook Formula
Save the following 6 lines into friction.m m-file.
function dummy %this allows you to pack the 5 lines below into a single m-file.
fsolve(@cole, 0.02) %fsolve looks for cole function below. If missing, it looks in current directory.
function y=cole(f)
eoverD=0.000375;
Re=1.37e+4;
y=1/sqrt(f)+2*log10(eoverD/3.7 + 2.51/Re/sqrt(f));

Run friction.m in Matlab
>>friction.m
f =
    0.0291


Using fsolve for a nonlinear equation system

The problem below is from a multiple pipe system in ChE345 (Fluid Mechanics.)
Save the 7 lines below as a file named fluids.m to be run in Matlab.
function dummy  %This allows you to pack the 6 lines below into a single m-file
x0=[1,1,1];
fsolve(@mflow,x0)  %fsolve looks for mflow function below. If missing, it looks in current directory.
function z=mflow(v)
z(1)=v(1)-v(2)-v(3);
z(2)=322 -v(1)^2-0.4*v(3)^2;
z(3)=258 -v(1)^2-0.5*v(2)^2;

Run the m-file to get three velocities. 
>> fluids
ans =
   15.9327    2.8802   13.0526

The same problem can be solved using the solve command.
Save the 4 lines in equations.m m-file.
e1='x1 = x2 + x3';
e2='322 = x1^2+0.4*x3^2';
e3='258 = x1^2+0.5*x2^2';
[x1,x2,x3]=solve(e1,e2,e3)
>>equations
x1 =
 -15.932742209168131268551587928289
 -5.6655931029670086917448152900978
  5.6655931029670086917448152900978
  15.932742209168131268551587928289
 
x2 =
 -2.8801825276159898268394750195246
  21.255637124848206348954897950637
 -21.255637124848206348954897950637
  2.8801825276159898268394750195246
  
x3 =
 -13.052559681552141441712112908765
 -26.921230227815215040699713240735
  26.921230227815215040699713240735
  13.052559681552141441712112908765
"solve" is not as robust as "fsolve" in MATLAB.
When you copy text from WORD or html to Matlab, be careful! You may carry over some hidden symbols. Use a notepad file to copy them. 


Another example using fsolve to solve 6 nonlinear equations

This is for Problem 8.64 on p. 374 of ChE345 (Fluid Mechanics) textbook.
How to solve Homework Problem 8.64* using Matlab's fsolve?

Save the 10 text lines below as solution.m file.
function dummy
x0=[1,1,1,0.02,0.02,0.02];
fsolve(@fcn,x0)
function z=fcn(x)
z(1)=x(1)-0.64*x(2)-0.64*x(3);%x(1)=v1, x(2)=v2, x(3)=v3
z(2)=40-102*x(4)*x(1)^2 - 127*x(5)*x(2)^2; %x(4)=f1, x(5)=f2, x(6)=f3
z(3)=60-102*x(4)*x(1)^2 - 255*x(6)*x(3)^2;
z(4)=1/sqrt(x(4))+2.0*log10(1.22e-4 +2.81e-5/x(1)/sqrt(x(4))); %Colebrook for f1
z(5)=1/sqrt(x(5))+2.0*log10(1.52e-4 +3.52e-5/x(2)/sqrt(x(5))); %Colebrook for f2
z(6)=1/sqrt(x(6))+2.0*log10(1.52e-4 +3.52e-5/x(3)/sqrt(x(6))); %Colebrook for f3
Run solution.m in Matlab
>>solution
ans =
    3.5001    2.6915    2.7774    0.0179    0.0192    0.0191

The answers are:
v1=3.500 m/s, v2=2.692 m/s, v3=2.777 m/s
f1=0.0179, f2=0.0192, f3=0.0191