How to solve second-degree algebraic equation containing elements of struct arrays?

1 次查看(过去 30 天)
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_omega = 0.1745
Delta_theta = -Delta_omega
Delta_theta = -0.1745
% 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)
c = -1.3336e+03
k1 = b^2 + c^2;
k2 = a*b;
k3 = a^2 - c^2;
lambda = k2^2 - k1*k3
lambda = 3.8064e+13
%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!
S = struct with fields:
k1: [0×1 sym] k2: [0×1 sym]
% 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!

采纳的回答

KSSV
KSSV 2022-3-2
syms k1 k2 k3
eqn = k1 * cos(ell1.theta)^2 + 2*k2 * cos(ell1.theta)^2 + k3
S = solve(eqn)
  2 个评论
Giuseppe
Giuseppe 2022-3-2
I followed your coding but I get a wrong result, becasue the unknown is cos(theta_1) and not k1 and k2.
How to fix this?
KSSV
KSSV 2022-3-2
syms theta
eqn = k1 * cos(theta)^2 + 2*k2 * cos(theta)^2 + k3 == 0;
S = solve(eqn,theta) % cos(ell1.theta) is the unknown!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by