## SUMMARY

Language : Matlab 2018b; Authors : Autar Kaw and Luis Serrano; Mfile available at http://nm.mathforcollege.com/blog/NonlinearEquations_withSetUp.m; 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.

```clc
clear all
```

## INTRODUCTION

```disp('ABSTRACT')
disp('   This program shows you how to solve')
disp('   a nonlinear equation that needs to be setup')
disp(' ')
disp('AUTHORS')
disp('   Autar Kaw and Luis Serrano')
disp(' ')
disp('MFILE SOURCE')
disp('   http://nm.mathforcollege.com/blog/NonlinearEquations_withSetUp.m')
disp(' ')
disp('LAST REVISED')
disp('   January 22, 2020')
disp(' ')
```
```ABSTRACT
This program shows you how to solve
a nonlinear equation that needs to be setup

AUTHORS
Autar Kaw and Luis Serrano

MFILE SOURCE
http://nm.mathforcollege.com/blog/NonlinearEquations_withSetUp.m

LAST REVISED
January 22, 2020

```

## INPUTS

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

```S=0.6
R=0.055
```
```S =

0.6000

R =

0.0550

```

## DISPLAYING INPUTS

```disp('INPUTS')
func=['  The equation to be solved is 4*R^3*S=3*x^2*(R-x/3)'];
disp(func)
disp('  ')
```
```INPUTS
The equation to be solved is 4*R^3*S=3*x^2*(R-x/3)

```

## THE CODE

Define x as a symbol

```syms x
% Setting up the equation
C1=4*R^3*S
C2=3*x^2*(R-x/3)
f=C1==C2
% Finding the solution of the nonlinear equation
soln=vpasolve(f,x);
solnvalue=double(soln);
```
```C1 =

3.9930e-04

C2 =

-3*x^2*(x/3 - 11/200)

f =

7365784908632225/18446744073709551616 == -3*x^2*(x/3 - 11/200)

```

## DISPLAYING OUTPUTS

```disp('OUTPUTS')
for i=1:1:length(solnvalue)
fprintf('\nThe solution# %g is %g',i,solnvalue(i))
end
disp('  ')
```
```OUTPUTS

The solution# 1 is -0.0437371
The solution# 2 is 0.0623776
The solution# 3 is 0.14636
```