Guest co-blogger: Luis Serrano
Many students ask me how do I do this or that in MATLAB. So I thought why not have a small series of my next few blogs do that. In this blog, I show you how to solve a nonlinear equation that needs to be set up.
For example to find the depth ‘x’ to which a ball is floating in water is based on the following cubic equation
R= radius of ball
S= specific gravity of ball
So how do we set this up if S and R are input values?
The MATLAB program link is here.
The HTML version of the MATLAB program is here.
- DO NOT COPY AND PASTE THE PROGRAM BELOW BECAUSE THE SINGLE QUOTES DO NOT TRANSLATE TO THE CORRECT SINGLE QUOTES IN MATLAB EDITOR. DOWNLOAD THE MATLAB PROGRAM INSTEAD
% Language : Matlab 2018b;
% Authors : Autar Kaw and Luis Serrano;
% Mfile available at
% Last Revised : January 22, 2020;
% Abstract: This program shows you how to solve a nonlinear equation
% that needs to set up as opposed that is just given to you.
disp(‘ This program shows you how to solve’)
disp(‘ a nonlinear equation that needs to be setup’)
disp(‘ Autar Kaw and Luis Serrano’)
disp(‘ January 22, 2020’)
% Solve the nonlinear equation where you need to set up the equation
% For example to find the depth ‘x’ to which a ball is floating in water is based on the following
% cubic equation 4*R^3*S=3*x^2*(R-x/3) R= radius of ball S= specific gravity of ball So how do we set this up if S and R are input values
%% DISPLAYING INPUTS
func=[‘ The equation to be solved is 4*R^3*S=3*x^2*(R-x/3)’];
%% THE CODE
% Define x as a symbol
% Setting up the equation
% Finding the solution of the nonlinear equation
%% DISPLAYING OUTPUTS
fprintf(‘\nThe solution# %g is %g’,i,solnvalue(i))
This post is brought to you by
- Holistic Numerical Methods Open Course Ware:
- the textbooks on
- the Massive Open Online Course (MOOCs) available at