I keep getting 4 answers per variable in 4x1 sym

11 visualizaciones (últimos 30 días)
Brandon
Brandon el 21 de Sept. de 2024
Comentada: Umar el 23 de Sept. de 2024
I have this system of equations but for the AlphaS, BetaS, and F2S I need one number but 4 keep popping out and I cant figure it out any tips will help!
% Given Data
L = 225; % Length of the ship in meters
B = 32; % Beam of the ship in meters
T = 12; % Draft of the ship in meters
v = 0.5; % Current speed in m/s
Cd = 0.4; % Drag coefficient
rho = 1025; % Density of water in kg/m^3
mu = 0.2; % Coefficient of sliding friction
Fp = 28000; % Fender reaction force in Newtons (28 kN)
F1 = 27500; % Bow mooring line force in Newtons (27.5 kN)
x = 0.4385 * L; % Distance from bow where fender acts
% Step 1: Calculate the drag force FD
A = B * T; % Cross-sectional area of the ship in m^2
FD = 0.5 * rho * v^2 * Cd * A; % Drag force in Newtons
% Step 2: Calculate fender friction force FF
FF = mu * Fp;
% Step 3: Set up equations for equilibrium
syms alpha beta F2
% Horizontal force balance equation
eq1 = -F1 * cos(alpha) + F2 * cos(beta) + FD - FF == 0;
% Vertical force balance equation
eq2 = -F1 * sin(alpha) - F2 * sin(beta) + Fp == 0;
% Moment balance equation about point 2 Clockwise positive
eq3 = -F1 * sin(alpha) * (L - (L/8) - (L/10)) + Fp * (L - (L/8) - (L/10) - x) + FF * (B/2) == 0;
% Solve the system of equations
[AlphaS, BetaS, F2S] = solve([eq1, eq2, eq3], [alpha, beta, F2]);
% Convert angles from radians to degrees and ensure positivity
alpha_deg = double(rad2deg(AlphaS))
beta_deg = double(rad2deg(BetaS))
F2_value = double(rad2deg(F2S))
  1 comentario
Umar
Umar el 23 de Sept. de 2024

Hi @Brandon,

Let me break down John D’Errico’s insights to clarify your concerns further. He has more years of technical expertise and knowledge. He has provided some excellent key points such as:

Multiple Solutions in Trigonometry

As noted, trigonometric functions such as sine and cosine are periodic, meaning they can yield multiple angles for a given value. This is why you see four distinct solutions when you solve for AlphaS and BetaS. It’s essential to understand that while all solutions are mathematically valid, you will need to determine which one fits your physical context.

Understanding Forces versus Angles

Your attempt to convert the force (F2S) from Newtons to degrees was identified as an error. Forces should remain in their units (Newtons), while angles should be expressed in degrees or radians as appropriate. This distinction is crucial to prevent bugs in your calculations.

Selecting the Appropriate Solution

Among the four solutions provided for AlphaS and BetaS, you will need to choose based on practical considerations related to your ship's configuration and operational context. Typically, the solution that keeps both angles within the first quadrant (0° to 90°) is most applicable for real-world scenarios.

If you require further assistance from us, please feel free to reach out!

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 21 de Sept. de 2024
Editada: John D'Errico el 22 de Sept. de 2024
L = 225; % Length of the ship in meters
B = 32; % Beam of the ship in meters
T = 12; % Draft of the ship in meters
v = 0.5; % Current speed in m/s
Cd = 0.4; % Drag coefficient
rho = 1025; % Density of water in kg/m^3
mu = 0.2; % Coefficient of sliding friction
Fp = 28000; % Fender reaction force in Newtons (28 kN)
F1 = 27500; % Bow mooring line force in Newtons (27.5 kN)
x = 0.4385 * L; % Distance from bow where fender acts
% Step 1: Calculate the drag force FD
A = B * T; % Cross-sectional area of the ship in m^2
FD = 0.5 * rho * v^2 * Cd * A; % Drag force in Newtons
% Step 2: Calculate fender friction force FF
FF = mu * Fp;
% Step 3: Set up equations for equilibrium
syms alpha beta F2
% Horizontal force balance equation
eq1 = -F1 * cos(alpha) + F2 * cos(beta) + FD - FF == 0;
% Vertical force balance equation
eq2 = -F1 * sin(alpha) - F2 * sin(beta) + Fp == 0;
% Moment balance equation about point 2 Clockwise positive
eq3 = -F1 * sin(alpha) * (L - (L/8) - (L/10)) + Fp * (L - (L/8) - (L/10) - x) + FF * (B/2) == 0;
% Solve the system of equations
[AlphaS, BetaS, F2S] = solve([eq1, eq2, eq3], [alpha, beta, F2]);
These are trig functions. MULTIPLE SOLUTIONS ARE ENTIRELY EXPECTED!
alpha_deg = double(rad2deg(AlphaS))
alpha_deg = 4×1
27.4370 152.5630 27.4370 152.5630
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
beta_deg = double(rad2deg(BetaS))
beta_deg = 4×1
-123.9676 -21.7167 56.0324 158.2833
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Um, why in the name of god and little green apples are you trying to convert a FORCE from radians to degrees?
F2_value = double(rad2deg(F2S))
F2_value = 4×1
1.0e+06 * -1.0590 -2.3736 1.0590 2.3736
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I'm sorry, but that just seems a bit ridiculous. F2S will have units of force, Newtons. Converting it to degrees is meaningless. My guess is, you were just in a rut there, not thinking about what you were doing. But that is the kind of thing that creates bugs, which later on, you will need to find. Or, possibly be the subject of another anxious question on the forum. Think more carefully when you write code.
As far as 4 solutions is concerned, why are you surprised? These are trig functions. Of course there are multiple solutions. In fact, there will be infinitely many solutions, but only 4 of them would be considered principal in any way.
Pick the solution you prefer. All 4 of them are technically solutions to your problem as posed. Very likely, only one of them will make sense in context of your particular problem. That might be the 3rd solution, where both angles will point in the first quadrant. But that is entirely your choice.
  1 comentario
John D'Errico
John D'Errico el 21 de Sept. de 2024
Editada: John D'Errico el 22 de Sept. de 2024
Think about it like this. Suppose you wanted to solve for the solution of
cos(x) == 0.5
Yes, you yould use acos. In fact, acos(0.5) yields one solution. We could call it the principal solution.
acos(0.5)
ans = 1.0472
That would be at 60 degrees, since you like degrees. Get used to working in radians, and you might become a happy mathematician in the end. ;-)
fplot(@cos,[0,2*pi])
grid on
yline(0.5,'-r')
The red line and the blue curve show there are in fact two solutions we might have seen. one of them at pi/3 radians (60 degrees) and the other at 5*pi/3 radians (300 degrees). And of coiurse cos or cosd both agree.
cos([pi/3,5*pi/3])
ans = 1×2
0.5000 0.5000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
cosd([60,300])
ans = 1×2
0.5000 0.5000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Now suppose we use solve. It tells us the same thing, and tells us there are infinitely many such solutions, all separated by integer multiples of 2*pi radians.
syms x
xsol = solve(cos(x) == 0.5,returnconditions = true)
xsol = struct with fields:
x: [2x1 sym] parameters: k conditions: [2x1 sym]
xsol.x
And now we see an infinite family of solutions, but they fall into two general classes. So solve returns TWO solutions.
What did solve tell you when you tried to solve your trig problem? It found 4 classes of solutions. But solve has no idea which solution you prefer. Computers don't read minds at all well.

Iniciar sesión para comentar.


Umar
Umar el 21 de Sept. de 2024

Hi @Brandon,

You mentioned, “I have this system of equations but for the AlphaS, BetaS, and F2S I need one number but 4 keep popping out and I cant figure it out any tips will help!”

Please see my response to your comments below.

Let me address your query regarding, 4 keep popping out and I cant figure it out

The solve function in MATLAB is designed to find all possible solutions for the equations provided, which is why you are seeing multiple outputs. I do agree with @John D'Errico’s comments above. Please see attached.

Now addressing your query about, I have this system of equations but for the AlphaS, BetaS, and F2S I need one number

To resolve this, you can apply constraints or specify initial guesses for the variables to guide the solver towards a unique solution. For instance, you can limit the range of AlphaS and BetaS to realistic angles (e.g., between 0 and π/2) or use the vpasolve function, which provides numerical solutions and can help in finding a specific solution based on initial values. For more information on vpasolve function, please refer to

https://www.mathworks.com/help/symbolic/sym.vpasolve.html

Here’s a refined version of your code

% Given Data
L = 225; % Length of the ship in meters
B = 32; % Beam of the ship in meters
T = 12; % Draft of the ship in meters
v = 0.5; % Current speed in m/s
Cd = 0.4; % Drag coefficient
rho = 1025; % Density of water in kg/m^3
mu = 0.2; % Coefficient of sliding friction
Fp = 28000; % Fender reaction force in Newtons (28 kN)
F1 = 27500; % Bow mooring line force in Newtons (27.5 kN)
x = 0.4385 * L; % Distance from bow where fender acts
% Step 1: Calculate the drag force FD
A = B * T; % Cross-sectional area of the ship in m^2
FD = 0.5 * rho * v^2 * Cd * A; % Drag force in Newtons
% Step 2: Calculate fender friction force FF
FF = mu * Fp;
% Step 3: Set up equations for equilibrium
syms alpha beta F2
% Horizontal force balance equation
eq1 = -F1 * cos(alpha) + F2 * cos(beta) + FD - FF == 0;
% Vertical force balance equation 
eq2 = -F1 * sin(alpha) - F2 * sin(beta) + Fp == 0;
% Moment balance equation about point 2 Clockwise positive
eq3 = -F1 * sin(alpha) * (L - (L/8) - (L/10)) + Fp * (L - (L/8) - (L/10) - x) +   FF * (B/2) == 0;
% Solve the system of equations
[AlphaS, BetaS, F2S] = vpasolve([eq1, eq2, eq3], [alpha, beta, F2]);
% Convert angles from radians to degrees and ensure positivity
alpha_deg = double(rad2deg(AlphaS))
beta_deg = double(rad2deg(BetaS))
F2_value = double(rad2deg(F2S))

Please see attached.

Please let me know if you have any further questions.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by