Effacer les filtres
Effacer les filtres

Trying to Solve system of 2 Equations "Unable to find explicit solution" Code In Description

1 vue (au cours des 30 derniers jours)
Code pasted below, thanks in advance:
clear all;
close all;
clc;
% Solve System of Equations
syms a1 a2 a3 r_1 r_2 alpha E
a3 = (alpha*E)/(8*pi);
[sol_a1, sol_a2] = solve(2*a3*log(r_1) + (a1/(r_1)^2) + a3 + 2*a2 == 0,...
2*a3*log(r_2) + (a1/(r_2)^2) + a3 + 2*a2 == 0);
Warning: Unable to find explicit solution. For options, see help.

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Nov 2023
syms a1 a2 a3 r_1 r_2 alpha E
a3 = (alpha*E)/(8*pi);
eqn = [2*a3*log(r_1) + (a1/(r_1)^2) + a3 + 2*a2 == 0,...
2*a3*log(r_2) + (a1/(r_2)^2) + a3 + 2*a2 == 0];
partial_1 = solve(eqn(1), a1)
partial_1 = 
eqn2 = subs(eqn(2:end), a1, partial_1)
eqn2 = 
partial_2 = solve(eqn2(1), a2)
partial_2 = 
sol_a2 = partial_2
sol_a2 = 
sol_a1 = subs(partial_1, a2, sol_a2)
sol_a1 = 
%cross-check
subs(eqn, {a1, a2}, {sol_a1, sol_a2})
ans = 
isAlways(ans)
ans = 1×2 logical array
1 1
%or... more directly...
syms a1 a2 a3 r_1 r_2 alpha E
a3 = (alpha*E)/(8*pi);
[sol_a1, sol_a2] = solve(2*a3*log(r_1) + (a1/(r_1)^2) + a3 + 2*a2 == 0,...
2*a3*log(r_2) + (a1/(r_2)^2) + a3 + 2*a2 == 0, [a1, a2])
sol_a1 = 
sol_a2 = 
simplify(sol_a1)
ans = 
simplify(sol_a2)
ans = 
  4 commentaires
Michael Meyne
Michael Meyne le 5 Nov 2023
I have a quick question, how do you get the solution to be printed with this formatting?
Walter Roberson
Walter Roberson le 6 Nov 2023
When you have a sym() or symfun() or symmatrix() expression, then that sort of formatting happens automatically if you are using LiveScript or MATLAB Online or MATLAB Answers. It does not happen if you are using the traditional command window (and there is no way to turn it on for the command window)

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 4 Nov 2023
Modifié(e) : Sulaymon Eshkabilov le 4 Nov 2023
Note that you have six unknowns (a1, a2, r_1, r_2, alpha, E) an two equations. It is possible to get two solution type expressions using IgnoreAnalyticalConstraints option, e.g.:
syms a1 a2 r_1 r_2 alpha E
a3 = (alpha*E)/(8*pi);
SOLUTION = solve(2*a3*log(r_1) + (a1/(r_1)^2) + a3 + 2*a2 == 0,...
2*a3*log(r_2) + (a1/(r_2)^2) + a3 + 2*a2 == 0, "IgnoreAnalyticConstraints",true)
SOLUTION = struct with fields:
r_1: exp(-((E*alpha)/2 + 8*pi*a2)/(E*alpha))*exp(wrightOmega(log(-(8*pi*a1)/(E*alpha)) + (E*alpha + 16*pi*a2)/(E*alpha))/2) r_2: exp(-((E*alpha)/2 + 8*pi*a2)/(E*alpha))*exp(wrightOmega(log(-(8*pi*a1)/(E*alpha)) + (E*alpha + 16*pi*a2)/(E*alpha))/2)
r_1 = SOLUTION.r_1
r_1 = 
r_2 = SOLUTION.r_2
r_2 = 
a3 = (alpha*E)/(8*pi)
a3 = 

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by