# How do I solve an equation with an unknown variable?

27 views (last 30 days)

Show older comments

I have 4 known variables and 1 unknown, but I'm not sure how to solve for it:

v=70

ro=1.225

Sw=5

c=0.5

Here is my equation:

-18==0.5*ro*(v^2)*Sw*c*CM_ac

CM_ac is unknown, how do i solve for it? Are there certain math toolboxes required?

##### 0 Comments

### Answers (4)

Dyuman Joshi
on 18 Sep 2023

Edited: Dyuman Joshi
on 18 Sep 2023

You can use fzero

v=90; % velocity

ro=1.225; % density at sea level, kg/m^3

Sw=3; % wing area, m^2

c=0.4; % chord, m

%Defining an anonymous function to solve for

%fzero solves for F(x)=0, so we convert out function accordingly

fun = @(x) 0.5*ro*(v^2)*Sw*c*x - (-19)

%fzero requires an initial point to start the search for the solution

CM_ac = fzero(fun,0)

syms CM_ac

v=90; % velocity

ro=1.225; % density at sea level, kg/m^3

Sw=3; % wing area, m^2

c=0.4; % chord, m

eqn = -19==0.5*ro*(v^2)*Sw*c*CM_ac;

CM_ac = solve(eqn,CM_ac)

The output you get is a symbolic number.

class(CM_ac)

To change into a numeric data type, use a data type -

%Using the default numeric data type of MATLAB

CM_ac = double(CM_ac)

##### 0 Comments

Harry
on 18 Sep 2023

This isn't a coding problem, but a mathematical problem. Because you have only 1 unknown variable, to solve this all you need to do is rearrange your equation to make CM_ac the subject. To do this, we can divide both sides of the equation by the known values (as each value is multiplied together):

% Initial

-18 = 0.5 * ro * (v^2) * Sw * c * CM_ac

% Divide both sides by ( 0.5 * ro * (v^2) * Sw * c )

-18 / (0.5 * ro * (v^2) * Sw * c ) = CM_ac

% Put the unknown on the left side instead

CM_ac = -18 / ( 0.5 * ro * (v^2) * Sw * c )

Alternatively, you could just manually swap each known letter for its value, and simplify your equation.

Putting the following code into matlab will solve your question. However, this problem is fairly basic formula manipulation they teach in high school.

% State known values

v=70; ro=1.225; Sw=5; c=0.5;

% Find CM_ac

CM_ac = -18 / ( 0.5 * ro * (v^2) * Sw * c )

##### 3 Comments

Torsten
on 18 Sep 2023

Harry
on 18 Sep 2023

That's not the initial question you asked. But as others have suggested, there are ways to solve it in matlab.

Sounds like you have a more interesting problem though, but we need more information. How many equations do you have? Are they always the same equation or different ones? Is there always one unknown variable? What does the data input look like?

Sam Chak
on 18 Sep 2023

Hi @TC

Yes, there is a useful function called 'isolate()' in Symbolic Math Toolbox. If you want to do this iteratively, please post the true problem.

syms r_o v S_w c CM_ac

% write the equation:

eqn = - 18 == 0.5 * r_o * (v^2) * S_w * c * CM_ac

% isolate CM_ac in the equation

CM_ac_Sol = isolate(eqn, CM_ac)

% substitute the symbolic variables with values: ro = 1.225, v = 70, Sw = 5, c = 0.5

CM_ac_Sol = subs(CM_ac_Sol, {r_o, v, S_w, c}, {1.225, 70, 5, 0.5})

% return the solution in floating-point number with 4 significant digits

vpa(CM_ac_Sol, 4)

##### 0 Comments

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!