How to solve second-degree algebraic equation containing elements of struct arrays?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys,
in my script I have two struct arrays and I want to solve a second-degree algebraic equations that involves some their fields.
I tried to use the symbolic toolbox but it seems not working with struct arrays.
Here is my script:
clc; clear all; close all
% Definition of data structures for two ellipses (attempt with numbers, at the end )
% Under planar approximation the so-called Keplerian elements set just
% consists of a, e, ω, and θ. Instead of a, e, we can also give in input
% r_p and r_a
% First ellipse
ell1.a = 30000; % (km)
ell1.e = 0.6;
ell1.r_p = 12000; % (km)
ell1.r_a = 2*ell1.a - ell1.r_p;
ell1.omega = deg2rad(0); % (rad)
ell1.theta = deg2rad(10); % (rad)
ell1.p = ell1.a*(1-ell1.e^2); % (km)
% Second ellipse
ell2.a = 24000; % (km)
ell2.e = 0.4;
ell2.r_p = 9000 ; % (km)
ell2.r_a = 2*ell2.a - ell2.r_p;
ell2.omega = deg2rad(10); % (rad)
ell2.theta = deg2rad(45); % (rad)
ell2.p = ell2.a*(1-ell2.e^2); % (km)
% Necessary condition to find intersections: e1 =/ e2
% Relative geometry for confocal ellipses
Delta_omega = ell2.omega - ell1.omega % relative orientation between two ellipses
Delta_theta = -Delta_omega
% Equation to obtain the intersections between two ellipses represented
% by the Keplerian elements sets (a1, e1,ω1) and (a2, e2, ω2)
% Auxiliary parameters
a = ell1.p - ell2.p;
b = ell1.p * ell2.e * cos(Delta_omega) - ell2.p * ell1.e;
c = -ell1.p * ell2.e * sin(Delta_omega)
k1 = b^2 + c^2;
k2 = a*b;
k3 = a^2 - c^2;
lambda = k2^2 - k1*k3
%Solve the second-degree algebraic equation, where cosθ_1 is the unknown,
% by using the "Symbolic Math Toolbox"
syms k1 k2 k3
eqn = k1 * cos(ell1.theta)^2 + 2*k2 * cos(ell1.theta)^2 + k3 == 0;
S = solve(eqn,cos(ell1.theta)) % cos(ell1.theta) is the unknown!
% Old not working part
% syms k1 k2 k3 ell1.theta
%
% eqn = k1 * cos(ell1.theta)^2 + 2*k2 * cos(ell1.theta)^2 + k3
% S = solve(eqn)
Can you help me, please?
Edit: code corrected!
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!