Solving inequalities without Symbolic Math Toolbox
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Andrik Rampun
il 8 Apr 2019
Commentato: Andrik Rampun
il 9 Apr 2019
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
0 Commenti
Risposta accettata
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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!