Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
weird calculating result from symbolic equation when using parenthesis
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I am getting a very weird result when using the symbolic library to generate some equations.
apc6 is calculated incorrectly when i use parenthesis: apc6 = (-CC(1:N)-(AC(1:N)-FC(1:N))); and correctly when I dont: apc6 = (-CC(1:N)-AC(1:N)-FC(1:N));
could someone please clarify why this occurs?
Many thanks, Jesse
clear
N=1;
FC = sym('FC',[1,N]); % coal fuel cost €/MWh
CC = sym('CC',[1,N]); % CO2 fee €/MWh
SC = sym('SC',[1,N]); % Startup costs
AC = sym('AC',[1,N]); % Additional costs
%The start costs vector
ep = ones(1,N)*6.17;
%The start costs vector
sc6 = ones(1,N)*5000;
% sc(1)=0; %%Enable if block is off at t=0
%The fixed costs vector
ac6 = ones(1,N)*1.9;
%The fuel costs vector
fc = ones(1,N)*10.28;
%CO2 cost vector
cc = ones(1,N).*6.17';
%%Sanity Check
ap6 = (-AC(1:N)-FC(1:N));
apc6 = (-CC(1:N)-(AC(1:N)-FC(1:N))); %%INCORRECT RESULT
%apc6 = (-CC(1:N)-AC(1:N)-FC(1:N)); %%CORRECT RESULT
ap6 = subs(ap6,[FC;AC],[fc';ac6']);
apc6 = subs(apc6,[CC;FC;AC],[cc';fc';ac6']);
double(ap6)
double(apc6)
double(ap6) - double(apc6)
댓글 수: 0
답변 (1개)
Titus Edelhofer
2014년 12월 17일
Hi Jesse,
these are two different things. Slightly simpler example:
x1 = a - (b - c)
and
x2 = a - b - c
are two different things. You need to take the "-" in front of the parenthesis into account
x2 = a - b - (-c) = a - b + c
would be correct ...
Titus
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!