Solving inequalities without Symbolic Math Toolbox

조회 수: 4 (최근 30일)
Andrik Rampun
Andrik Rampun 2019년 4월 8일
댓글: Andrik Rampun 2019년 4월 9일
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

채택된 답변

David Goodmanson
David Goodmanson 2019년 4월 9일
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
Andrik Rampun
Andrik Rampun 2019년 4월 9일
Thanks a lot David,
I got it work now and I can run my standalone program without the need of Symbolic Math Toolbox!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by