作者a29788685 (嘉峰)
看板Mathematica
標題Re: [問題] 將方程式輸出成CForm
時間Thu Oct 8 16:13:57 2015
試了好久,終於成功了,就讓我自問自答一下,
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
→ LPH66: 太慢看到了, 你可以用 StringJoin 在 Mathematica 裡先接好 10/08 18:18
→ LPH66: StringJoin["a", "b"] 會得到 "ab"; 用 "a"<>"b" 也是同義 10/08 18:19
→ LPH66: 所以你可以 WriteString["fn",word1<>CForm[Func]<>word2]; 10/08 18:20
→ LPH66: 一行即可輸出不須執行多行 10/08 18:20
→ a29788685: 謝謝!我會試看看! 10/09 19:11