Re: [問題] 將方程式輸出成CForm

看板Mathematica作者 (嘉峰)時間8年前 (2015/10/08 16:14), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串2/2 (看更多)
試了好久,終於成功了,就讓我自問自答一下, SetDirectory[NotebookDirectory[]]; (*先找到資料夾*) word1 = ToString["Double_t Func(Double_t *par){ return "]; word2 = ToString[";}"]; (*需要用到的文字先打上,並定義他在C中的函數名稱是Func*) DeleteFile["test"] (*先把test這個檔案刪掉,避免有其他東西在裡面*) WriteString["test", word1]; (*word1寫入*) Func // CForm >>> test; (*方程式寫入*) WriteString["test", word2]; (*word2寫入*) 在C程式碼的最頂端加入 # include "test" //檔案test必須和C程式碼在同一路徑 如此就可以在C中直接使用Func函數 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 103.5.101.7 ※ 文章網址: https://www.ptt.cc/bbs/Mathematica/M.1444292040.A.E5F.html

10/08 18:18, , 1F
太慢看到了, 你可以用 StringJoin 在 Mathematica 裡先接好
10/08 18:18, 1F

10/08 18:19, , 2F
StringJoin["a", "b"] 會得到 "ab"; 用 "a"<>"b" 也是同義
10/08 18:19, 2F

10/08 18:20, , 3F
所以你可以 WriteString["fn",word1<>CForm[Func]<>word2];
10/08 18:20, 3F

10/08 18:20, , 4F
一行即可輸出不須執行多行
10/08 18:20, 4F

10/09 19:11, , 5F
謝謝!我會試看看!
10/09 19:11, 5F
文章代碼(AID): #1M5YN8vV (Mathematica)
文章代碼(AID): #1M5YN8vV (Mathematica)