一応書いたには書いたのですが、どこかが間違っているようで上手く動きません。どこが間違っているか教えていただけないでしょうか。
こんな感じで逆行列から解を求める形にしたのですがどこを直せばいいのかわかりません。お願いします。
#include "hspmath.as" title "連立n元一次方程式を解く" font "MS 明朝",15 pos 10,0:input n,25,25:objsize 50,20:pos 35,0:button "決定",*gyouretu stop *gyouretu if (clear):clrobj objID(0),objID(1):objsize 50,20:pos 35,0:button "決定",*gyouretu //オブジェクトの消去と描写 nn = n color 255,255,255:boxf:color:pos 10,25:mes ""+nn+"連立元一次方程式" objID(0) = stat objsize 25,25 repeat nn //係数行列 cnt1 = cnt cnt_1 =cnt*nn repeat nn cnt_2 = cnt a(cnt_1+cnt_2) = cnt_1+cnt_2 pos 50+cnt_2*25,50+cnt1*25 input a(cnt_1+cnt_2),25,25 loop loop repeat nn //定数項 b(cnt) = cnt pos 50+nn*25+25,50+cnt*25 input b(cnt),25,25 loop pos 50,50+nn*25:mes "係数行列":pos 50+nn*25+25,50+nn*25:mes "定数項" objsize 50,20:pos 20,50+nn*25+25:button "結果",*keka objID(1) = stat clear = 1 stop *keka color 255,255,255:boxf 0,nn*25+25,640,nn*25+25 //解の初期化 //det(A)を求める repeat nn cnt_3 = cnt repeat nn cnt_4 = cnt if (cnt_4+cnt_3 != nn)&(p1 != 1):dapd(cnt_4) = a(cnt_4*nn + cnt_4+cnt_3) if (cnt_4+cnt_3 = nn)|(p1 = 1):dapd(cnt_4) = a(cnt_4*nn + cnt_4+cnt_3-nn):p1=1 loop p1 = 0 repeat nn-1 if (cnt = 0):dap_d(cnt_3) = dapd(cnt) if (cnt = 0):dap_(cnt_3) = dap_d(cnt_3) * dapd(cnt+1) if (cnt != 0):dap_(cnt_3) = dap_(cnt_3) * dapd(cnt+1) loop loop repeat nn dap += dap_(cnt) loop repeat nn cnt_5 = cnt repeat nn cnt_6 = cnt if (cnt_6+cnt_5 != nn)&(m1 != 1):damd(cnt_6) = a(cnt_6*nn + nn-1-cnt_6-cnt_5) if (cnt_6+cnt_5 = nn)|(m1 = 1):damd(cnt_6) = a(cnt_6*nn + nn-1-cnt_6-cnt_5+nn):m1=1 loop m1 = 0 repeat nn-1 if (cnt = 0):dam_d(cnt_5) = damd(cnt) if (cnt = 0):dam_(cnt_5) = dam_d(cnt_5) * damd(cnt+1) if (cnt != 0):dam_(cnt_5) = dam_(cnt_5) * damd(cnt+1) loop loop repeat nn dam += dam_(cnt) loop deta = dap - dam //det(A)が求まる if (deta = 0)::dialog "det(A)=0のため、解がない、もしくは解が複数存在します",1,"解なし":stop //余因子行列を求める repeat nn*nn cnt_12 = cnt //行列の要素の定義 repeat nn-1 cnt11 = cnt*(nn-1) cnt_11 = cnt*nn if (cnt_12-cnt_11 <= nn-1)&(cnt_12-cnt_11 >= 0):r=1 repeat nn-1 if (fmod(cnt_12,nn) = fmod(cnt,nn))|(g = 1):a_(cnt11+cnt) = a(cnt_11+cnt+1):g=1 if (r = 1):a_(cnt11+cnt) = a(cnt_11+cnt+nn) if (g = 1)&(r = 1):a_(cnt11+cnt) = a(cnt_11+cnt+nn+1) if (g != 1)&(r != 1):a_(cnt11+cnt) = a(cnt_11+cnt) loop g = 0 loop r = 0 repeat nn-1 cnt_7 = cnt repeat nn-1 cnt_8 = cnt if (cnt_8+cnt_7 != nn-1)&(p2 != 1):ydapd(cnt_8) = a_(cnt_8*(nn-1) + cnt_8+cnt_7) if (cnt_8+cnt_7 = nn-1)|(p2 = 1):ydapd(cnt_8) = a_(cnt_8*(nn-1) + cnt_8+cnt_7-(nn-1)):p2=1 loop p2 = 0 repeat nn-1-1 if (cnt = 0):ydap_d(cnt_7) = ydapd(cnt) if (cnt = 0):ydap_(cnt_7) = ydap_d(cnt_7) * ydapd(cnt+1) if (cnt != 0):ydap_(cnt_7) = ydap_(cnt_7) * ydapd(cnt+1) loop loop repeat nn-1 ydap(cnt_12) += ydap_(cnt) loop repeat nn-1 cnt_9 = cnt repeat nn-1 cnt_10 = cnt if (cnt_10+cnt_9 != nn-1)&(m2 != 1):ydamd(cnt_10) = a_(cnt_10*(nn-1) + (nn-1)-1-cnt_10-cnt_9) if (cnt_10+cnt_9 = nn-1)|(m2 = 1):ydamd(cnt_10) = a_(cnt_10*(nn-1) + (nn-1)-1-cnt_10-cnt_9+(nn-1)):m2=1 loop m2 = 0 repeat nn-1-1 if (cnt = 0):ydam_d(cnt_9) = ydamd(cnt) if (cnt = 0):ydam_(cnt_9) = ydam_d(cnt_9) * ydamd(cnt+1) if (cnt != 0):ydam_(cnt_9) = ydam_(cnt_9) * ydamd(cnt+1) loop loop repeat nn-1 ydam(cnt_12) += ydam_(cnt) loop ydeta(cnt_12) = ydap(cnt_12)-ydam(cnt_12) //余因子行列が求まる(順番はまだ) loop repeat nn //余因子行列の順番も決定 cnt_13 = cnt*nn cnt13 = cnt repeat nn if (fmod(cnt,2) = 0)&(fmod(cnt13,2) = 0){ deta_(cnt_13+cnt) = ydeta(cnt*nn + cnt13) }else:deta_(cnt_13+cnt) = -ydeta(cnt*nn + cnt13) if (fmod(cnt,2) = 0)&(fmod(cnt13,2) != 0){ deta_(cnt_13+cnt) = -ydeta(cnt*nn + cnt13) }else:deta_(cnt_13+cnt) = ydeta(cnt*nn + cnt13) loop loop //逆行列算出 repeat nn*nn gyaku(cnt) = double(deta_(cnt))/double(deta) loop //解の算出 repeat nn cnt_14 = cnt*nn repeat nn x_(cnt+cnt_14) = double(gyaku(cnt+cnt_14)) * double(b(cnt)) loop loop repeat nn cnt_15 = cnt repeat nn x(cnt_15) += double(x_(cnt)) loop loop repeat nn //解の表示 color:mes "x"+cnt+"="+x(cnt)+" loop stop