Solving inequalities without Symbolic Math Toolbox

2 visualizzazioni (ultimi 30 giorni)
Hi All,
I just realised that Matlab compiler does not support Symbolic Math Toolbox after running my executable file. Is there any alternative of solving inequalities without using Symbolic Math Toolbox?
Here's my source code
syms a b c
eq1 = a*xCoords(1)^2+b*xCoords(1)+c; % equation 1
eq2=a*xCoords(2)^2+b*xCoords(2)+c;% equation 2
eq3=a*xCoords(3)^2+b*xCoords(3)+c; % equation 3
final_eq = solve([eq1==yCoords(1), eq2==yCoords(2), eq3 == yCoords(3)]);
var_a = abs(final_eq.a);
var_b = (final_eq.b);
var_c = (final_eq.c);
It's a simple program to solve three quadratic equations (eventually to get three other variables). I wonder if my code can be rewriten without using Symbolic Math Toolbox?
Thanks a lot

Risposta accettata

David Goodmanson
David Goodmanson il 9 Apr 2019
Hi Andrik,
I'm not sure why you are calling these equations 'inequalities', but if you are looking for a numerical solution to this, then you can use the backslash solution method that Matlab was basically founded on.
xCoords = [4 2 7]';
yCoords = [1 3 -4]';
syms a b c
eq1 = a*xCoords(1)^2+b*xCoords(1)+c; % equation 1
eq2=a*xCoords(2)^2+b*xCoords(2)+c;% equation 2
eq3=a*xCoords(3)^2+b*xCoords(3)+c; % equation 3
final_eq = solve([eq1==yCoords(1), eq2==yCoords(2), eq3 == yCoords(3)]);
var_a = abs(final_eq.a)
var_b = (final_eq.b)
var_c = (final_eq.c)
% numerical linalg solution
% form the vandermonde matrix (xCoords and yCoords are column vectors)
vander = [xCoords.^2 xCoords ones(size(xCoords))]
abc = vander\yCoords % abc(1) = var_a, etc.
The linalg solution gives the same result except in double precision rather than the fractions produced by sym. Also the sign of var_a is different because the linalg solution has not yet taken the absolute value of that variable.
  1 Commento
Andrik Rampun
Andrik Rampun il 9 Apr 2019
Thanks a lot David,
I got it work now and I can run my standalone program without the need of Symbolic Math Toolbox!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by