Solve a quadratic equation

5 vues (au cours des 30 derniers jours)
Mepe
Mepe le 20 Fév 2020
Commenté : Mepe le 20 Fév 2020
So far I have solved the equation below with fsolve (with the help of this forum).
tau = 0.1
f4 = [3; 2; 6; 8]
f8 = [2; 6; 7; 3]
eq = @(s,f4,f8) s*tau-(0.1.*s^2+3.54.*s-9.53).*f4.^2-f8;
for f = 1:1:length (f4)
F1 (f,:) = fsolve (@(s)eq(s,f4(f),f8(f)), 0);
end
Unfortunately, only a solution of the quadratic equation is given here. I didn't get along with the command roots () because my "formulas" were not accepted here. Does anyone have an idea here how elegantly all solutions can be found?

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 20 Fév 2020
Modifié(e) : Alex Mcaulley le 20 Fév 2020
To use the function roots you need to reformulate your equation:
tau = 0.1
f4 = [3; 2; 6; 8]
f8 = [2; 6; 7; 3]
eq = @(f4,f8) [-0.1*f4^2, -3.54*f4^2 + tau,9.53*f4^2-f8];
sol = zeros(numel(f4),2);
for f = 1:1:length(f4)
sol(f,:) = roots(eq(f4(f),f8(f)));
end
>> sol
sol =
-37.7542 2.4654
-37.3027 2.1527
-37.8394 2.4672
-37.8874 2.5030
  1 commentaire
Mepe
Mepe le 20 Fév 2020
Works perfect. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Partial Differential Equation Toolbox 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!

Translated by