Commit c4edc110 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Avoid redundancy in code

parent f83bef10
......@@ -16,12 +16,14 @@
matrix_sum/3,
create_diag_matrix/3,
sub_matrix/1,
row_sum/3,
transpose_matrix/2,
lusubst/2,
solve_linear_problem/3
]
).
:- use_module(util).
/* Module Matrix
*
* Several operations are done on a "global variable" of SWI-prolog (using nb_set/getval)
......@@ -323,17 +325,10 @@ matrix_apply([Row|Matrix],Vector,[ResultElement|ResultVector]):-
matrix_sum([],[],[]).
matrix_sum([RowA|MatrixA],[RowB|MatrixB],[SumRow|SumMatrix]):-
row_sum(RowA,RowB,SumRow),
add_list(RowA,RowB,SumRow),
matrix_sum(MatrixA,MatrixB,SumMatrix).
row_sum([],[],[]).
row_sum([ElementA|RowA],[ElementB|Row2],[SumElement|SumRow]):-
SumElement is ElementA+ElementB,
row_sum(RowA,Row2,SumRow).
%! create_diag_matrix(+Size, +Value, -Diag_matrix)
%
% Store a diagonal matrix in the global variable and return it
......
......@@ -919,6 +919,11 @@ test_condition(State,Time,Condition1 or Condition2,Result) :-
Result = false
).
%! apply_changes(State, Time, Condition)
%
% to be called when an events is triggered
apply_changes(State,Time, Parameter = (if Condition then IfTrue else IfFalse)) :-
test_condition(State,_,Condition,Result),
(
......@@ -938,6 +943,12 @@ apply_changes(State,Time, Parameter = Expression) :-
nb_setval(parameters_list,NewParameters).
/****************/
/* Euler method */
/****************/
%! euler(+Equations, +Time, +CurrentState, +CurrentTable)
euler(Equations,Time,CurrentState,CurrentTable) :-
format("One event occured ~n",[]),
retractall(euler_last_state(_,_)),
......@@ -965,11 +976,14 @@ euler(Equations,Time,CurrentState,CurrentTable) :-
),
nb_setval(last_time,TimeNewState).
%! euler_step(+Equations, +CurrentState, +StepSize, +Parameters, -NewCurrentState)
euler_step(Equations,CurrentState,StepSize,Parameters,NewCurrentState) :-
eval_state(CurrentState,Parameters,EvaluatedCurrentState),
eval_row(Equations,CurrentState,Parameters,EvaluatedEquations),
multiply_list(EvaluatedEquations,StepSize,TrueEvaluatedEquations),
row_sum(EvaluatedCurrentState,TrueEvaluatedEquations,NewCurrentState).
add_list(EvaluatedCurrentState,TrueEvaluatedEquations,NewCurrentState).
/*:- doc('\\begin{example}Ball simulation using event:').
:- biocham_silent(clear_model).
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment