Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

wrong solution trying to solve a system of algebric equations

조회 수: 1 (최근 30일)
Daniele
Daniele 2019년 6월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi,
trying to solve a system of 8 algebric equations, using the 'solve' function, but apparentely none of the 4 solutions found by Matlab satisfies all the input equations. In particular, if the equation system is:
eqs=[eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8];
and the line where I call 'solve' is:
[a,b,c,d,e,f,g,epeak,parameters,conditions]=solve(eqs,[a,b,c,d,e,f,g,epeak],'ReturnConditions',true);
all the solutions found by Matlab seem to not-satisfy eq4.
To better understand, here it is the code I wrote:
clearvars
clc
syms x a b c d e f g E fc epeak Gf h
% polynomials
cub=a*(x^3)+b*(x^2)+c*x+d; % cubic curve
quad=e*(x^2)+f*x+g; % quadratic curve
d_cub=diff(cub,x); % cubic curve derivate
d_quad=diff(quad,x); % quadratic curve derivative
d2_cub=diff(d_cub,x); % cubic curve second derivative
d2_quad=diff(d_quad,x); % quadratic curve second derivative
% shortcuts
cub_0 =subs(cub,x,0); % cubic curve value at 0
cub_fcE =subs(cub,x,fc/E); % cubic curve at fc/E
quad_fcE =subs(quad,x,fc/E); % quadratic curve at fc/E
quad_epeak =subs(quad,x,epeak); % quadratic curve at epeak
d_cub_0 =subs(d_cub,x,0); % cubic curve slope at 0
d_cub_fcE =subs(d_cub,x,fc/E); % cubic curve slope at fc/E
d_quad_fcE =subs(d_quad,x,fc/E); % quadratic curve slope at fc/R
d_quad_epeak =subs(d_quad,x,epeak); % quadratic curve slope at epeak
d2_cub_fcE =subs(d2_cub,x,fc/E); % cubic curve concavity
d2_quad_fcE =subs(d2_quad,x,fc/E); % quadratic curve concavity
% boundary conditions
eq1= cub_0==0; % cubic value at origin = 0
eq2= d_cub_0==E; % cubic curve slope at origin = E
eq3= quad_epeak==fc; % cubic curve at epeak = fc
eq4= d_quad_epeak==0; % quadratic curve slope at epeak = 0
eq5= cub_fcE==quad_fcE; % intersections of curves at fc/E
eq6= d_cub_fcE==d_quad_fcE; % curves have same slopes at intersection
eq7= d2_cub_fcE==d2_quad_fcE;% same concavity at intersection
eq8= int(cub,x,0,fc/E)+int(quad,x,fc/E,epeak)==(Gf/h);% area undercurves
eqs=[eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8];
[a_,b_,c_,d_,e_,f_,g_,epeak_,params,conds]=solve(eqs,[a,b,c,d,e,f,g,epeak],'ReturnConditions',true);
% test on eq4 = quad_epeak == 0
Nsolutions=size(a_,1);
test_=zeros(2,1);
test_=sym(test_);
for i=1:Nsolutions
d_quad_epeak=subs(d_quad_epeak,a,a_(i));
d_quad_epeak=subs(d_quad_epeak,b,b_(i));
d_quad_epeak=subs(d_quad_epeak,c,c_(i));
d_quad_epeak=subs(d_quad_epeak,d,d_(i));
d_quad_epeak=subs(d_quad_epeak,e,e_(i));
d_quad_epeak=subs(d_quad_epeak,f,f_(i));
d_quad_epeak=subs(d_quad_epeak,g,g_(i));
d_quad_epeak=subs(d_quad_epeak,epeak,epeak_(i));
display(simplify(d_quad_epeak)); % ans = 0, but substituting real values it returns a non-zero value
d_quad_epeak=subs(d_quad_epeak,E,1491); % input value for E
d_quad_epeak=subs(d_quad_epeak,fc,6.2); % input value for fc
fprintf('test on eq4 returns: %s\n',d_quad_epeak); % it should be zero!
end
As you can see above, eq4 is: d_quad_epeak==0, but substituting the 8 parameters found by Matlab, d_quad_epeak is always about 3.6e-12.
Is it the system I'm trying to solve bad conditioned, or is it an approximation problem, or I did something wrong using the 'solve' function?
  댓글 수: 1
Torsten
Torsten 2019년 7월 1일
Trust in "solve". The error you get when substituting values for the variables is due to the limited floating point precision.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by