Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

weird calculating result from symbolic equation when using parenthesis

1 view (last 30 days)
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)

Answers (1)

Titus Edelhofer
Titus Edelhofer on 17 Dec 2014
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

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!