private void bt_ConvertActionPerformed(java.awt.event.ActionEvent evt) {
NewEnvironmentMacro.addNewEnvironment("multline", "\\multline@@env{", "}", 0);
if (txtInput.getText().equals("")) {
JOptionPane.showMessageDialog(rootPane, "HÌnh như bạn chưa điền phương trình.\nHãy nhập phương trình và chúng tôi sẽ giải quyết nó cho bạn.");
} else {
// biến lưu dạng pt do người dùng nhập
String input = txtInput.getText();
// mapleCode
String mapleCode = "restart:\n"
+ "#---------------------------------- TIỀN XỬ LÝ ------------------------------------\n"
+ "chuyenVePt := proc (fString)\n"
+ " local ep; \n"
+ " ep := parse(fString);\n"
+ " ep := lhs(ep) - rhs(ep) = 0;\n"
+ " return convert(ep, string);\n"
+ "end proc:\n"
+ "\n"
+ "taoChuoi := proc(str, L)\n"
+ " uses StringTools;\n"
+ " local new_str, n, i, temp;\n"
+ " new_str := str;\n"
+ " n := numelems(L);\n"
+ " for i from 1 to n do\n"
+ " temp := cat(\"{\", convert(i, string), \"}\");\n"
+ " new_str := Substitute(new_str, temp, L[i]);\n"
+ " end do;\n"
+ " return new_str;\n"
+ "end proc:\n"
+ "\n"
+ "getSetOfChar := proc()\n"
+ " local charExpr, s;\n"
+ " uses StringTools;\n"
+ " charExpr := \"()*+-_./0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ^abcdefghijklmnopqrstuvwxyz\"; \n"
+ " s := {seq(charExpr[i], i=1..length(charExpr))};\n"
+ " return s;\n"
+ "end proc:\n"
+ "tien_xu_ly := proc(str) \n"
+ " local setOfChars, new_str, c;\n"
+ " uses StringTools; \n"
+ " # xóa kí tự thừa\n"
+ " setOfChars := getSetOfChar();\n"
+ " new_str := \"\";\n"
+ " for c in str do\n"
+ " if (c = \"'\") or (c in setOfChars) then\n"
+ " new_str := cat(new_str, c);\n"
+ " end if;\n"
+ " end do;\n"
+ " # thay thế ' bằng _ \n"
+ " new_str := Substitute(new_str, \"'\", \"_\");\n"
+ " # thêm dấu bằng \n"
+ " if Search(\"=\", new_str) = 0 then\n"
+ " new_str := cat(new_str, \"=0\");\n"
+ " else \n"
+ " new_str := chuyenVePt(new_str);\n"
+ " end if; \n"
+ " return new_str;\n"
+ "end proc:\n"
+ "\n"
+ "getLeft := proc(fString)\n"
+ " local f;\n"
+ " f := parse(fString);\n"
+ " return convert(lhs(f), string);\n"
+ "end proc:\n"
+ "\n"
+ "getLatex := proc(f)\n"
+ " return cat(\"\\\\(\", latex(f, output=string), \"\\\\)\"); \n"
+ "end proc:\n"
+ "\n"
+ "#---------------------------------------------------------------------------------\n"
+ "#---------------------------------- NHẬN DẠNG ------------------------------------\n"
+ "\n"
+ "# ví dụ: xy = yu + xs thì input là: xy - yu - xs\n"
+ "# Ví dụ: y' = y / x + e^(y / x) thì input là: y' - y / x - e^(y / x)\n"
+ "\n"
+ "check2 := proc(f, var1, var2)\n"
+ " local vars, g;\n"
+ " g := subs(var1 = 1, f);\n"
+ " g := subs(var2 = 21, g);\n"
+ " g := subs(e = 0, g);\n"
+ " vars := indets(g); \n"
+ " return evalb(numelems(vars) = 0);\n"
+ "end proc:\n"
+ "\n"
+ "check := proc(f, var)\n"
+ " local vars, g;\n"
+ " g := subs(var = 0.1653001562, f);\n"
+ " g := subs(e = 0.1653001562, g);\n"
+ " vars := indets(g); \n"
+ " return evalb(numelems(vars) = 0);\n"
+ "end proc:\n"
+ "\n"
+ "check_tach_bien := proc (fString) \n"
+ " local fx, gy, f; \n"
+ " uses StringTools; \n"
+ " if evalb(0 < Search(\"y_\", fString)) then \n"
+ " return [false];\n"
+ " end if; \n"
+ " f := parse(fString); \n"
+ " fx := coeff(f, dx, 1); \n"
+ " gy := coeff(f, dy, 1); \n"
+ " if check(fx, x) and check(gy, y) then \n"
+ " return [true, fx, gy];\n"
+ " else \n"
+ " return [false] \n"
+ " end if; \n"
+ "end proc:\n"
+ "\n"
+ "check_dang_cap := proc(fString) \n"
+ " local g, gString, f; \n"
+ " uses StringTools;\n"
+ " if evalb(0 = Search(\"y_\", fString)) then \n"
+ " return [false];\n"
+ " end if; \n"
+ " gString := Subs(\"y_\" = \"0\", fString):\n"
+ " g := parse(gString):\n"
+ " g := algsubs(y/x = u, g):\n"
+ " if check(g, u) then\n"
+ " return [true, parse(gString)];\n"
+ " end if;\n"
+ " return [false];\n"
+ "end proc:\n"
+ "\n"
+ "check_tuyen_tinh_cap_1 := proc(fString)\n"
+ " local g, gString, px, qx;\n"
+ " uses StringTools;\n"
+ " try \n"
+ " if evalb(0 = Search(\"y_\", fString)) then \n"
+ " return [false];\n"
+ " end if; \n"
+ " gString := Subs(\"y_\" = \"0\", fString):\n"
+ " g := parse(gString): \n"
+ " px := coeff(g, y, 1); \n"
+ " qx := expand(px * y) - expand(g); \n"
+ " if check(px, x) and check(qx, x) then\n"
+ " return [true, px, qx];\n"
+ " end if;\n"
+ " catch:\n"
+ " printf(\"Bị lỗi \\n \");\n"
+ " return [false];\n"
+ " end try;\n"
+ " return [false];\n"
+ "end proc:\n"
+ "\n"
+ "check_bernouli := proc(fString)\n"
+ " local f, g, beta, alpha, remind, gString, i, px, qx;\n"
+ " uses StringTools;\n"
+ " try \n"
+ " if Search(\"y_\", fString) = 0 then \n"
+ " return [false];\n"
+ " end if; \n"
+ " # Xóa y'\n"
+ " gString := Subs(\"y_\" = \"0\", fString):\n"
+ " g := parse(gString);\n"
+ " f := expand(g / y); \n"
+ " \n"
+ " remind := expand(g) - expand(f * y);\n"
+ " if remind != 0 then\n"
+ " return [false];\n"
+ " end if; \n"
+ " # tim alpha \n"
+ " px := coeff(f, y, 0);\n"
+ " f := expand(f) - expand(px); \n"
+ " g := coeffs(f, y); \n"
+ " if numelems({g}) != 1 then\n"
+ " return [false];\n"
+ " end if;\n"
+ " alpha := -10; \n"
+ " for beta from -5 to 5 do\n"
+ " if expand(g * (y ^ beta)) = expand(f) then\n"
+ " alpha := beta + 1;\n"
+ " break;\n"
+ " end if;\n"
+ " end do; \n"
+ " if alpha = -10 then \n"
+ " return [false];\n"
+ " end if;\n"
+ " qx := -g; \n"
+ " if check(px, x) and check(qx, x) then\n"
+ " return [true, px, qx, alpha];\n"
+ " end if;\n"
+ " catch:\n"
+ " printf(\"Bị lỗi \\n \");\n"
+ " return [false];\n"
+ " end try;\n"
+ " return [false]; \n"
+ "end proc:\n"
+ "\n"
+ "check_vi_phan_toan_phan := proc(fString)\n"
+ " local pxy, qxy, f;\n"
+ " f := parse(fString); \n"
+ " pxy := coeff(f, dx, 1);\n"
+ " qxy := coeff(f, dy, 1); \n"
+ " if check2(pxy, x, y) and check2(qxy, x, y) then\n"
+ " return [true, pxy, qxy];\n"
+ " else\n"
+ " return [false];\n"
+ " end if;\n"
+ "end proc:\n"
+ "\n"
+ "nhan_dien := proc(gString)\n"
+ " local f, fString;\n"
+ " fString := tien_xu_ly(gString); \n"
+ " fString := getLeft(fString);\n"
+ " f := check_tach_bien(fString);\n"
+ " if f[1] = true then\n"
+ " return [\"tach_bien\", f[2], f[3]];\n"
+ " end if;\n"
+ " f := check_dang_cap(fString);\n"
+ " if f[1] = true then\n"
+ " return [\"dang_cap\", f[2]];\n"
+ " end if;\n"
+ " f := check_tuyen_tinh_cap_1(fString);\n"
+ " if f[1] = true then\n"
+ " return [\"tuyen_tinh\", f[2], f[3]];\n"
+ " end if;\n"
+ " f := check_bernouli(fString);\n"
+ " if f[1] = true then\n"
+ " return [\"bernouli\", f[2], f[3], f[4]];\n"
+ " end if; \n"
+ " f := check_vi_phan_toan_phan(fString);\n"
+ " if f[1] = true then\n"
+ " return [\"toan_phan\", f[2], f[3]];\n"
+ " end if;\n"
+ " return [\"unknown\"];\n"
+ "end proc:\n"
+ "\n"
+ "#---------------------------------------------------------------------------------\n"
+ "#---------------------------------- BỘ GIẢI TOÁN ------------------------------------\n"
+ "giaiPtTachBien:=proc(L)\n"
+ " local fxPf, gyPf, raw, resEx, Fx, Gy, \n"
+ " rawPf, int_expr_Pf, resPf;\n"
+ " local _res;\n"
+ " \n"
+ " Fx := L[1]; Gy := L[2];\n"
+ " printf(\"Phương trình của bạn là phương trình tách biến \\n \");\n"
+ " _res := \"Phuong trinh cua ban la phuong trinh tach bien \\n \";\n"
+ " fxPf := getLatex(Fx);\n"
+ " gyPf := getLatex(Gy);\n"
+ " printf(\"Ta đưa phương trình về dạng: \\n \");\n"
+ " _res := cat(_res, \"Ta dua phuong trinh ve dang: \\n \");\n"
+ " raw := Fx*dx + Gy*dy;\n"
+ " rawPf := getLatex(raw, output=string);\n"
+ " printf(\"%s = 0\", rawPf);\n"
+ " _res := cat(_res, taoChuoi(\"{1} = 0\", [rawPf]));\n"
+ " printf(\" \\n Tiếp theo ta tính nguyên hàm 2 vế: \\n \"); \n"
+ " _res := cat(_res, \" \\n Tiep theo ta tinh nguyen ham 2 ve: \\n \");\n"
+ " int_expr_Pf := getLatex(Int(Fx, x) + Int(Gy, y));\n"
+ " printf(\"%s = 0\", int_expr_Pf);\n"
+ " _res := cat(_res, taoChuoi(\"{1} = 0 \", [int_expr_Pf]));\n"
+ " printf(\" \\n Vậy, nghiệm tổng quát của phương trình là: \\n \");\n"
+ " _res := cat(_res, \" \\n Vay, nghiem tong quat cua phuong trinh la: \\n \");\n"
+ " resEx := int(Fx,x) + int(Gy,y) = C;\n"
+ " resPf := getLatex(resEx);\n"
+ " printf(resPf); \n"
+ " _res := cat(_res, resPf);\n"
+ " return _res;\n"
+ "end proc:\n"
+ "\n"
+ "dang_cap := proc(L)\n"
+ " local FxPf, fuPf, fu, u, resTB, Fx;\n"
+ " local resPf;\n"
+ " local _res;\n"
+ " \n"
+ " Fx := -L[1]; \n"
+ " printf(\"Phương trình của bạn là phương trình đẳng cấp \\n \");\n"
+ " _res := \"Phuong trinh cua ban la phuong trinh dang cap \\n \";\n"
+ " FxPf := getLatex(Fx); \n"
+ " printf(\"Phương trình của bạn là: y' = %s \\n \", FxPf);\n"
+ " _res := cat(_res, taoChuoi(\"Phuong trinh cua ban la: y' = {1} \\n \", [FxPf]));\n"
+ " printf(\"Các bước giải: \\n \");\n"
+ " _res := cat(_res, \"Cac buoc giai: \\n \");\n"
+ " printf(\"Đặt u = y/x => y = u.x => y' = u + xu' \\n \"); \n"
+ " _res := cat(_res, \"Dat u = y/x => y = u.x => y' = u + xu' \\n \");\n"
+ " printf(\"Thay y' vào phương trình đầu ta được: \\n \");\n"
+ " _res := cat(_res, \"Thay y' vao phuong trinh dau ta duoc: \\n \");\n"
+ "\n"
+ " fu := algsubs(y / x = u, Fx) - u;\n"
+ " fuPf := getLatex(fu);\n"
+ " printf(\"xu' = %s \\n \", fuPf);\n"
+ " _res := cat(_res, taoChuoi(\"xu' = {1} \\n \", [fuPf]));\n"
+ " printf(\"Đây là phương trình tách biến, ta sẽ giải dựa theo phương trình tách biến \\n \");\n"
+ " _res := cat(_res, \"Day la phuong trinh tach bien, ta se giai dua theo phuong trinh tach bien \\n \");\n"
+ " fu := algsubs(u = y, fu); \n"
+ " resTB := giaiPtTachBien([-1/x, 1/fu]);\n"
+ " printf(\"Giải phương trình tách biến trên ta được \\n \");\n"
+ " _res := cat(_res, \"Giai phuong trinh tach bien tren ta duoc \\n \");\n"
+ " \n"
+ " resTB := algsubs(y = u, resTB);\n"
+ " resPf := getLatex(getTB);\n"
+ " printf(\"%s \\n \", resPf);\n"
+ " _res := cat(_res, taoChuoi(\"{1} \\n \", [resPf]));\n"
+ " \n"
+ " resTB := algsubs(u = y / x, resTB);\n"
+ " resPf := getLatex(resTB); \n"
+ " printf(\"Tương đương với: %s \\n \", resPf);\n"
+ " _res := cat(_res, taoChuoi(\"Tuong duong voi: {1} \\n \", [resPf]));\n"
+ " return _res;\n"
+ "end proc:\n"
+ "\n"
+ "tuyen_tinh_cap_1 := proc(L) \n"
+ " local PxPf, QxPf, aPf, yPf, y, res1, res2, a, C, Px, Qx;\n"
+ " local _res;\n"
+ " \n"
+ " Px := L[1];\n"
+ " Qx := L[2];\n"
+ " printf(\"Phương trình của bạn là phương trình tuyến tính cấp 1 \\n \");\n"
+ " _res := \"Phuong trinh cua ban la phuong trinh tuyen tinh cap 1 \\n \";\n"
+ " \n"
+ " PxPf := getLatex(Px);\n"
+ " QxPf := getLatex(Qx);\n"
+ " printf(\"Phương trình của bạn là: y' + (%s)y = %s \\n \", PxPf, QxPf);\n"
+ " _res := cat(_res, taoChuoi(\"Phuong trinh cua ban la: y' + ({1})y = {2} \\n \", [PxPf, QxPf]));\n"
+ " \n"
+ " printf(\"Các bước giải: \\n \");\n"
+ " _res := cat(_res, \"Cac buoc giai: \\n \");\n"
+ " printf(\"Đầu tiên, mình tính nguyên hàm của: %s, \\n Đặt nó là a. Ta có: \\n \", PxPf);\n"
+ " _res := cat(_res, taoChuoi(\"Dau tien, minh tinh nguyen ham cua {1}, \\n Dat no la a. Ta co: \\n \", [PxPf]));\n"
+ " a := int(Px, x);\n"
+ " aPf := getLatex(Int(Px, x));\n"
+ " printf(\"<=> a = %s \\n \", aPf);\n"
+ " _res := cat(_res, taoChuoi(\"<=> a = {1} \\n \", [aPf]));\n"
+ " yPf := getLatex(exp(-a) * (Int(Qx * exp(a), x)) + C);\n"
+ " printf(\"Vậy kết quả là: y = %s \\n \", yPf);\n"
+ " _res := cat(_res, taoChuoi(\"Vay ket qua la: y = {1} \\n \", [yPf]));\n"
+ " y := exp(-1 * a) * (int(Qx * exp(a), x) + C);\n"
+ " res1 := getLatex(y);\n"
+ " printf(\"=> y = %s \\n \", res1);\n"
+ " _res := cat(_res, taoChuoi(\"=> y = {1} \\n \", [res1]));\n"
+ " res2 := getLatex(expand(y));\n"
+ " if length(res1) > length(res2) then\n"
+ " printf(\"<=> y = %s\", res2);\n"
+ " _res := cat(_res, taoChuoi(\"<=> y = {1}\", [res2]));\n"
+ " end if;\n"
+ " return [y, _res];\n"
+ "end proc:\n"
+ "\n"
+ "bernouli := proc(L)\n"
+ " local PxPf, QxPf, aPf, z, zPf, diff_z, diff_y, y;\n"
+ " local main_expr,diff_z_before, expr_ps, _Px, _Qx, Px, Qx, alpha;\n"
+ " local exprPf, daoHamZY, daoHamZYPf, yPf;\n"
+ " local _res; \n"
+ " \n"
+ " Px := L[1];\n"
+ " Qx := L[2];\n"
+ " alpha := L[3];\n"
+ "\n"
+ " printf(\"Phương trình của bạn là phương trình bernouli \\n \"); \n"
+ " _res := \"Phuong trinh cua ban la phuong trinh bernouli \\n \";\n"
+ " PxPf := getLatex(Px);\n"
+ " QxPf := getLatex(Qx);\n"
+ " aPf := getLatex(alpha);\n"
+ " \n"
+ " main_expr := diff_y + Px * y = Qx * (y ^ alpha);\n"
+ " exprPf := getLatex(Px * y = Qx * y ^ alpha);\n"
+ " \n"
+ " printf(\"Phương trình của bạn là: y' + %s (1) \\n \", exprPf);\n"
+ " _res := cat(_res, taoChuoi(\"Phuong trinh cua ban la: y' + {1} (1) \\n \", [exprPf]));\n"
+ " printf(\"Các bước giải: \\n \");\n"
+ " _res := cat(_res, \"Cac buoc giai: \\n \");\n"
+ " z := y ^ (1 - alpha);\n"
+ " zPf := getLatex(z); \n"
+ " printf(\"Đặt z = %s \\n \", zPf); \n"
+ " _res := cat(_res, taoChuoi(\"Dat z = {1} \\n \", [zPf]));\n"
+ " daoHamZY := diff(z, y);\n"
+ " daoHamZYPf := getLatex(Diff(z, y)); \n"
+ " printf(\"Suy ra, z' = (%s)y' \\n \", daoHamZYPf);\n"
+ " _res := cat(_res, taoChuoi(\"Suy ra, z' = ({1})y' \\n \", [daoHamZYPf]));\n"
+ " printf(\"Nhân cả 2 vế của phương trình (1) với %s, ta có: \\n \", daoHamZYPf); \n"
+ " _res := cat(_res, taoChuoi(\"Nhan ca 2 ve cua phuong trinh (1) voi {1}, ta co: \\n \", [daoHamZYPf]));\n"
+ " main_expr := expand(main_expr * daoHamZY);\n"
+ " exprPf := getLatex(main_expr);\n"
+ " printf(\"(1) <=> %s \\n \", exprPf);\n"
+ " _res := cat(_res, taoChuoi(\"(1) <=> {1} \\n \", [exprPf]));\n"
+ " \n"
+ " diff_z_before := _z * diff_y; \n"
+ " main_expr := algsubs(diff_z_before = _z, main_expr); \n"
+ " z := 'z';\n"
+ " main_expr := algsubs(y ^ (1 - alpha) = z, main_expr);\n"
+ "\n"
+ " exprPf := getLatex(main_expr);\n"
+ " printf(\"==> %s\", exprPf);\n"
+ " _res := cat(_res, taoChuoi(\"==> {1}\", [exprPf]));\n"
+ " printf(\"(Đây là phương trình tuyến tính cấp 1) \\n \");\n"
+ " _res := cat(_res, \"(Day la phuong trinh tuyen tinh cap 1) \\n \");\n"
+ " _Px := coeff(lhs(main_expr), z);\n"
+ " _Qx := rhs(main_expr);\n"
+ " \n"
+ " z := tuyen_tinh_cap_1([_Px, _Qx]);\n"
+ " _res := cat(_res, z[2]);\n"
+ " z := z[1];\n"
+ " zPf := getLatex(z); \n"
+ " printf(\" \\n z = %s\", zPf);\n"
+ " _res := cat(_res, taoChuoi(\" \\n z = {1}\", [zPf]));\n"
+ " \n"
+ " yPf := getLatex(y^(1-alpha) = z);\n"
+ " printf(\" \\n <=> %s\", yPf); \n"
+ " _res := cat(_res, taoChuoi(\" \\n <=> {1}\", [yPf]));\n"
+ "end proc:\n"
+ "\n"
+ "giai_ptviphan_toanphan := proc(L) \n"
+ " local pxyPf, qxyPf, diff_Pxy, diff_Qxy, int_Py, int_Qx;\n"
+ " local res, resPf, Pxy, Qxy, nguyenHamPxy, Diff_Uy;\n"
+ " local daoHam_nguyenHamPxy_theo_y, daoHam_c_y, c_y, int_Px;\n"
+ " local daoHamPYPf1, daoHamPY, daoHamPYPf2 , daoHamQXPf1, daoHamQX, daoHamQXPf2;\n"
+ " local nguyenHamPXPf1, nguyenHamPX, nguyenHamPXPf2, daoHamUYPf;\n"
+ " local daoHam_nguyenHamPxy_theo_yPf, daoHam_c_yPf, c_yPf;\n"
+ " local _res;\n"
+ " \n"
+ " uses StringTools;\n"
+ " Pxy := L[1];\n"
+ " Qxy := L[2];\n"
+ " \n"
+ " printf(\"Phương trình của bạn là phương trình vi phân toàn phần \\n \"); \n"
+ " _res := \"$\\mbox{Phuong trinh cua ban la phuong trinh vi phan toan phan}$ \\n \";\n"
+ " pxyPf := getLatex(Pxy);\n"
+ " qxyPf := getLatex(Qxy);\n"
+ " printf(\"Phương trình có dạng: (%s)dx + (%s)dy = 0 \\n \", pxyPf, qxyPf);\n"
+ " _res := cat(_res, taoChuoi(\"$\\mbox{Phuong trinh co dang: }${1}dx + {2}dy = 0 \\n \", [pxyPf, qxyPf]));\n"
+ " daoHamPYPf1 := getLatex(Diff(Pxy, y));\n"
+ " printf(\"Cách giải: \\n Tính %s \\n \", daoHamPYPf1); \n"
+ " _res := cat(_res, taoChuoi(\"$\\mbox{Cach giai: }$ \\n Tinh {1} \\n \", [daoHamPYPf1]));\n"
+ " daoHamPY := diff(Pxy, y); \n"
+ " daoHamPYPf2 := getLatex(daoHamPY); \n"
+ " printf(\"%s = %s (1) \\n \", daoHamPYPf1, daoHamPYPf2); \n"
+ " _res := cat(_res, taoChuoi(\"{1} = {2} (1) \\n \", [daoHamPYPf1, daoHamPYPf2]));\n"
+ " \n"
+ " daoHamQXPf1 := getLatex(Diff(Qxy, x));\n"
+ " printf(\"Tính %s \\n \", daoHamQXPf1); \n"
+ " _res := cat(_res, taoChuoi(\"Tinh {1} \\n \", [daoHamQXPf1]));\n"
+ " daoHamQX := diff(Qxy, x); \n"
+ " daoHamQXPf2 := getLatex(daoHamQX); \n"
+ " printf(\"Q'x = (%s) (2) \\n \", daoHamQXPf2); \n"
+ " _res := cat(_res, taoChuoi(\"Q'x = ({1}) (2) \\n \", [daoHamQXPf2]));\n"
+ " \n"
+ " # kiem tra 2 cai giong nhau\n"
+ " daoHamPY := sort(daoHamPY);\n"
+ " daoHamQX := sort(daoHamQX);\n"
+ " if daoHamPY = daoHamQX then \n"
+ " printf(\"%s = %s = %s \\n \", daoHamPYPf1, daoHamQXPf1, daoHamPYPf2);\n"
+ " _res := cat(_res, taoChuoi(\"{1} = {2} = {3} \\n \", [daoHamPYPf1, daoHamQXPf1, daoHamPYPf2]));\n"
+ " nguyenHamPXPf1 := getLatex(Int(Pxy, x));\n"
+ " printf(\"Từ (1) ta suy ra: U(x, y) = %s + c(y) \\n \", nguyenHamPXPf1);\n"
+ " _res := cat(_res, taoChuoi(\"Tu (1) ta suy ra: U(x, y) = {1} + c(y) \\n \", [nguyenHamPXPf1]));\n"
+ " nguyenHamPX := int(Pxy, x);\n"
+ " nguyenHamPXPf2 := getLatex(nguyenHamPX);\n"
+ " printf(\"=> U(x, y) = %s + c(y) \\n \", nguyenHamPXPf2);\n"
+ " _res := cat(_res, taoChuoi(\"=> U(x, y) = {1} + c(y) \\n \", [nguyenHamPXPf2]));\n"
+ " daoHamUYPf := getLatex(Diff(U, y));\n"
+ " daoHam_nguyenHamPxy_theo_y := diff(nguyenHamPX, y); \n"
+ " daoHam_nguyenHamPxy_theo_yPf := getLatex(Diff(nguyenHamPX, y));\n"
+ " printf(\"=> %s = %s + c'(y) = %s \\n \", daoHamUYPf, daoHam_nguyenHamPxy_theo_yPf, qxyPf);\n"
+ " _res := cat(_res, taoChuoi(\"=> {1} = {2} + c'(y) = {3}. \\n \", [daoHamUYPf, daoHam_nguyenHamPxy_theo_yPf, qxyPf]));\n"
+ " daoHam_c_y := Qxy - daoHam_nguyenHamPxy_theo_y;\n"
+ " daoHam_c_yPf := getLatex(daoHam_c_y); \n"
+ " printf(\"==> c'(y) = %s \\n \", daoHam_c_yPf); \n"
+ " _res := cat(_res, taoChuoi(\"==> c'(y) = {1}. \\n \", [daoHam_c_yPf]));\n"
+ " c_y := int(daoHam_c_y, y);\n"
+ " c_yPf := getLatex(Int(daoHam_c_y, y));\n"
+ " printf(\"==> c(y) = %s + c1 \\n \", c_yPf);\n"
+ " _res := cat(_res, taoChuoi(\"==> c(y) = {1} + c1. \\n \", [c_yPf]));\n"
+ " \n"
+ " res := nguyenHamPX + c_y;\n"
+ " res := subs(ln(e)=1, res);\n"
+ " resPf := getLatex(res);\n"
+ " printf(\"Vậy, kết quả là: U(x, y) = %s + c1 \\n \", resPf);\n"
+ " _res := cat(_res, taoChuoi(\"Vay, ket qua la: U(x, y) = {1} + c1. \\n \", [resPf]));\n"
+ " else\n"
+ " printf(\"Chương trình không có khả năng giải phương trình này.\");\n"
+ " _res := cat(_res, \"Chuong trinh khong co kha nang giai phuong trinh nay.\");\n"
+ " end if;\n"
+ " return _res;\n"
+ "end proc:\n"
+ "\n"
+ "#----------------------------------------------------------------------------------\n"
+ "#----------------------------------------MAIN--------------------------------------\n"
+ "\n"
+ "giai_phuong_trinh_vi_phan := proc(fString)\n"
+ " local argus, kind, methods;\n"
+ " local _res;\n"
+ " methods := table([\"tach_bien\" = giaiPtTachBien, \"dang_cap\" = dang_cap, \n"
+ " \"bernouli\" = bernouli, \"tuyen_tinh\" = tuyen_tinh_cap_1, \"toan_phan\" = giai_ptviphan_toanphan]); \n"
+ " argus := nhan_dien(fString); \n"
+ " kind := argus[1];\n"
+ " _res := \"\";\n"
+ " if kind = \"unknown\" then \n"
+ " printf(\"Chương trình không có khả năng giải phương trình này \\n \");\n"
+ " _res := \"Chuong trinh khong co kha nang giai phuong trinh nay. \\n \";\n"
+ " return ;\n"
+ " end if; \n"
+ " _res := cat(_res, methods[kind](argus[2..]));\n"
+ " return _res;\n"
+ "end proc:\n"
+ "\n"
+ "giai_phuong_trinh_vi_phan(\"" + input + "\");\n";
// y' + 2*x*y = 2*x*x*y*y*y
// kết nối Maple
String mapleArgs[];
Engine engine;
mapleArgs = new String[1];
mapleArgs[0] = "java";
Procedure p;
try {
engine = new Engine(mapleArgs, new EngineCallBacksDefault(), null, null);
String res = engine.evaluate(mapleCode).toString();
System.out.println("Đây là chuỗi trong ngoặc");
System.out.println(res);
String old_c = "\\n";
String new_c = "\\\\\\\\\\n ";
String final_res1 = res.replace(old_c, new_c);
System.out.println("\nSau khi thay thế \\n bằng \\\\\\\\\\n"); // thay \n bằng \\\\\n
System.out.println(final_res1);
String final_res2 = final_res1.replace('"', ' '); // loại bỏ dấu "
System.out.println(final_res2);
// show biểu thức toán học.
String latex1 = "" // biểu thức latex hoàn chỉnh
+ "\\begin{multline}\n"
+ final_res2
+ "\n\\end{multline}\n";
// System.out.println("Biểu thức latex của phương trình.");
// System.out.println(latex);
String latex = "\\begin{multline}"
+" Phuong trinh cua ban la phuong trinh tach bien \\\\\n Ta dua phuong trinh ve dang: \\\\\n \\(0\\) = 0 \\\\\n Tiep theo ta tinh nguyen ham 2 ve: \\\\\n \\(\\int \\!0\\,{\\rm d}x+\\int \\!0\\,{\\rm d}y\\) = 0 \\\\\n Vay, nghiem tong quat cua phuong trinh la: \\\\\n \\(0=C\\)"
+" \\end{multline}";
TeXFormula formula1 = new TeXFormula(latex);
// code dưới chạy được
// TeXFormula formula1 = new TeXFormula(""
// + " \\begin{multline}\n"
// + " $\\mbox{Phuong trinh cua ban la phuong trinh vi phan toan phan}$ \\\\\n "
// + " $\\mbox{Phuong trinh co dang: }$ (\\(0\\))dx + (\\(0\\))dy = 0 \\\\\n"
// + " $\\mbox{Cach giai: }\\\\\n"
// + " $\\mbox{Tinh }\\({\\frac {\\rm d}{{\\rm d}y}} \\left( 0 \\right) \\) \\\\\n"
// + " \\({\\frac {\\rm d}{{\\rm d}y}} \\left( 0 \\right) \\) = \\(0\\) (1) \\\\\n"
// + " $\\mbox{--Tinh \\({\\frac {\\rm d}{{\\rm d}x}} \\left( 0 \\right) \\) \\\\\n"
// + " Q'x = (\\(0\\)) (2) \\\\\n"
// + " \\({\\frac {\\rm d}{{\\rm d}y}} \\left( 0 \\right) \\) = \\({\\frac {\\rm d}{{\\rm d}x}} \\left( 0 \\right) \\) = \\(0\\) \\\\\n"
// + " Tu (1) ta suy ra: U(x, y) = \\(\\int \\!0\\,{\\rm d}x\\) + c(y) \\\\\n"
// + " => U(x, y) = \\(0\\) + c(y) \\\\\n"
// + " => \\({\\frac {\\rm d}{{\\rm d}y}}U\\) = \\({\\frac {\\rm d}{{\\rm d}y}} \\left( 0 \\right) \\) + c'(y) = \\(0\\) \\\\\n"
// + " ==> c'(y) = \\(0\\) \\\\\n"
// + " ==> c(y) = \\(\\int \\!0\\,{\\rm d}y\\) + c1 \\\\\n"
// + " Vay, ket qua la: U(x, y) = \\(0\\) + c1 "
// + "\\end{multline}\n");
TeXIcon t1 = formula1.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
BufferedImage b1 = new BufferedImage(t1.getIconWidth(), t1.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
t1.paintIcon(pn_kq, b1.getGraphics(), 0, 0);
lb_kq.setIcon(t1);
} catch (MapleException ex) {
JOptionPane.showMessageDialog(rootPane, ex.getMessage());
}
}
}