mac9

soluzione sistema lineare con kramer


 

* kramer1 */
/* soluzione sistema lineare due equazioni con kramer */
ese:-whide(kramer1),esegue.
esegue:-
dialog('sistema con kramer',50,50,200,300,
[button(150,20,20,60,'OK'),
 button(150,90,20,60,'cancella'),
 text(10,10,30,250,'scrivi coefficienti sistema:TAB..OK '),
 edit(45,20,16,50,'A1=',read(A1)),
 edit(45,80,16,50,'B1=',read(B1)),
 edit(45,150,16,50,'C1=',read(C1)),
 edit(90,20,16,50,'A2=',read(A2)),
 edit(90,80,16,50,'B2=',read(B2)),
 edit(90,150,16,50,'C2=',read(C2))],Btn),calcola(A1,B1,C1,A2,B2,C2),
 fine.
fine:-
wshow(kramer1).
calcola(A1,B1,C1,A2,B2,C2):-
write('soluzione sistema '),nl,
DS is (A1*B2-A2*B1),
DX is (C1*B2-C2*B1),
DY is (A1*C2-A2*C1),verifica(DS,DX,DY).
verifica(DS,DX,DY):-
DS ­ 0,
X is DX/DS,
Y is DY/DS,
write(['X=',X]),nl,
write(['Y=',Y]),nl,!,nl.
verifica(DS,DX,DY):-
DS = 0,(DX ­0;DY­0),
write(['sistema impossibile']),nl.
verifica(DS,DX,DY):-
DS = 0,(DX=0;DY=0),
write(['sistema indeterminato']),nl.

 

 

/* kramer4 */
/* soluzione sistema lineare due equazioni con kramer */
/* PIU COMPLETO */
esegue:-
kill_menu(scelta),
install_menu(scelta,[inizio,fine,dati]).
scelta(inizio):-whide(kramer1),wfront(user).
scelta(fine):-message('premi enter'),wfront(kramer1),wshow(kramer1).
scelta(dati):-
dialog('sistema con kramer',50,50,200,300,
[button(150,20,20,60,'OK'),
 button(150,90,20,60,'cancella'),
 text(10,10,30,250,'scrivi coefficienti sistema:TAB..OK '),
 edit(45,20,16,50,'A1=',read(A1)),
 edit(45,80,16,50,'B1=',read(B1)),
 edit(45,150,16,50,'C1=',read(C1)),
 edit(90,20,16,50,'A2=',read(A2)),
 edit(90,80,16,50,'B2=',read(B2)),
 edit(90,150,16,50,'C2=',read(C2))],Btn),
 calcola(A1,B1,C1,A2,B2,C2).
calcola(A1,B1,C1,A2,B2,C2):-
write('soluzione sistema '),nl,
write('sistema a due equazioni '),nl,
write('A1x   B1y   C1 '),nl,
write('A2x   B2y   C2 '),nl,
DS is (A1*B2-A2*B1),
DX is (C1*B2-C2*B1),
DY is (A1*C2-A2*C1),
write('-----------------------------------------------------'),nl,
write('coefficienti e termini noti delle equazioni'),nl,
fw(user,['~M',c(15),c(15),c(15)],['A1','B1','C1']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[A1,B1,C1]),nl,
fw(user,['~M',c(15),c(15),c(15)],['A2','B2','C2']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[A2,B2,C2]),nl,
write('-----------------------------------------------------'),nl,
write('determinanti sistema e incognite DS,DX,DY'),nl,
fw(user,['~M',c(15),c(15),c(15)],['DS','DX','DY']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[DS,DX,DY]),nl,
write('soluzione '),nl,
verifica(DS,DX,DY).
verifica(DS,DX,DY):-
DS ­ 0,
X is DX/DS,
Y is DY/DS,
fw(user,['~M',c(6),f(10,2)],['x=',X]),nl,
fw(user,['~M',c(6),f(10,2)],['y=',Y]),nl.
verifica(DS,DX,DY):-
DS = 0,(DX ­0;DY­0),
write(['sistema impossibile']),nl.
verifica(DS,DX,DY):-
DS = 0,(DX=0;DY=0),
write(['sistema indeterminato']),nl.

 

/* kramer5 */
/* soluzione sistema lineare due equazioni con kramer */
/* PIU COMPLETO con CANCELLAZIONE finestra soluzioni*/
esegue:-
kill_menu(scelta),
install_menu(scelta,[inizio,fine,dati,cancella]).
scelta(inizio):-whide(kramer1),wfront(user).
scelta(fine):-message('premi enter'),wfront(kramer1),wshow(kramer1).
scelta(cancella):-cursor(user,0,-1),clear(user).
scelta(dati):-
dialog('sistema con kramer',50,50,200,300,
[button(150,20,20,60,'OK'),
 button(150,90,20,60,'cancella'),
 text(10,10,30,250,'scrivi coefficienti sistema:TAB..OK '),
 edit(45,20,16,50,'A1=',read(A1)),
 edit(45,80,16,50,'B1=',read(B1)),
 edit(45,150,16,50,'C1=',read(C1)),
 edit(90,20,16,50,'A2=',read(A2)),
 edit(90,80,16,50,'B2=',read(B2)),
 edit(90,150,16,50,'C2=',read(C2))],Btn),
 calcola(A1,B1,C1,A2,B2,C2).
calcola(A1,B1,C1,A2,B2,C2):-
write('soluzione sistema '),nl,
write('sistema a due equazioni '),nl,
write('A1x   B1y   C1 '),nl,
write('A2x   B2y   C2 '),nl,
DS is (A1*B2-A2*B1),
DX is (C1*B2-C2*B1),
DY is (A1*C2-A2*C1),
write('-----------------------------------------------------'),nl,
write('coefficienti e termini noti delle equazioni'),nl,
fw(user,['~M',c(15),c(15),c(15)],['A1','B1','C1']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[A1,B1,C1]),nl,
fw(user,['~M',c(15),c(15),c(15)],['A2','B2','C2']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[A2,B2,C2]),nl,
write('-----------------------------------------------------'),nl,
write('determinanti sistema e incognite DS,DX,DY'),nl,
fw(user,['~M',c(15),c(15),c(15)],['DS','DX','DY']),nl,
fw(user,['~M',f(15,2),f(15,2),f(15,2)],[DS,DX,DY]),nl,
write('soluzione '),nl,
verifica(DS,DX,DY).
verifica(DS,DX,DY):-
DS ­ 0,
X is DX/DS,
Y is DY/DS,
fw(user,['~M',c(6),f(10,2)],['x=',X]),nl,
fw(user,['~M',c(6),f(10,2)],['y=',Y]),nl.
verifica(DS,DX,DY):-
DS = 0,(DX ­0;DY­0),
write(['sistema impossibile']),nl.
verifica(DS,DX,DY):-
DS = 0,(DX=0;DY=0),
write(['sistema indeterminato']),nl.