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

28 vues (au cours des 30 derniers jours)
TC le 18 Sep 2023
Commenté : Harry le 18 Sep 2023
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 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (4)

Dyuman Joshi le 18 Sep 2023
Modifié(e) : Dyuman Joshi le 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)
fun = function_handle with value:
@(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)
CM_ac = -0.0032
You can also use solve, but note that it requires the Symbolic Math Toolbox
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)
CM_ac =
The output you get is a symbolic number.
class(CM_ac)
ans = 'sym'
To change into a numeric data type, use a data type -
%Using the default numeric data type of MATLAB
CM_ac = double(CM_ac)
CM_ac = -0.0032
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

Torsten le 18 Sep 2023
Déplacé(e) : Torsten le 18 Sep 2023
I always use pencil and paper:
v=70 ;
ro=1.225 ;
Sw=5 ;
c=0.5 ;
CM_ac = -18/(0.5*ro*(v^2)*Sw*c)
CM_ac = -0.0024
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

Harry le 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 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Harry le 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?

Connectez-vous pour commenter.

Sam Chak le 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
eqn =
% isolate CM_ac in the equation
CM_ac_Sol = isolate(eqn, CM_ac)
CM_ac_Sol =
% 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})
CM_ac_Sol =
% return the solution in floating-point number with 4 significant digits
vpa(CM_ac_Sol, 4)
ans =
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Programming dans Help Center et File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by