%
% - File name : nonlin_onevar_4.m (Generated by Hee Jung : fall/1999)
% - Solve nonlinear equations of one variable
% - Example problem : solve (0.1*e^(x) + sin(x) -5 = x)
% - Method 4 : use MATLAB's symbolic solve command
% - Source of help on this solve command can be found in several places:
% 1) Pratap's MATLAB 5 book
% 2) type help solve in matlab command window
% 3) type helpdesk in matlab command window -> click on 'symbolic math toolbox ref.'
% in the web pages -> click the 'solve' function
%
clear % removes all variables from the workspace
%
% Solve one equation(eq1) with one unknown(var1).
% syntax of 'solve' function : solve('eq1','var1') or solve('eq1')
% As there's only one unknown, you don't need to specify the unknown variable name
%
% Define equations
eq1 = '0.1*exp(x)+sin(x)-5=x';
% Solve the problem with solve command. you type :
[x] = solve(eq1)
% you'll get, x = -4.1515936788037046341400951202097 which corresponds to one of the
% numeric solutions. It just doesn't find the other solution or give you a way
% to look for it. Basically, the solve command is not as good as the fzero
% command unless you are trying to get a symbolic answer.)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% < Note >
% 1. If there is more than one unknown variable, you had better include
% unknown variable names in using solve. If not, 'solve' function sometimes
% can not find a solution. But if there is only one variable, it doesn't matter.
% 2. If you try
% [output1,output2] = solve('eq1','eq2','var1,var2'),
% the output list is all out of order, so don't use this syntax.
% But if there is only one variable, [output1] = solve('eq1') is okay.
% 3. The solution of solve is generally given in symbolic form. But if there's
% no analytic solutions, solve will provide numerical solution.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%