Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
CodeGeneration[CSharp] - Maple コードを C# に変換
使い方
CSharp(x, cgopts)
パラメータ
x
-
式、リスト、rtable、プロシージャ、またはモジュール
cgopts
(オプション)CodeGeneration のオプションひとつまたは複数
説明
CSharp(x, cgopts) 呼び出しシーケンスは、Maple コードを C# コードに変換します。
- パラメータ x が数式の場合、式を変数に代入する C# 文を生成します。
- x がリスト、Maple 配列、または数式の rtable の場合は、要素を C# の配列に代入する C# 文の列が生成されます。rtable または Maple 配列の初期化された要素だけが変換されます。
- x が方程式 (ただし は名前、 は数式)の場合、代入文の列とみなし、同等の C# 代入文が生成されます。
- x がプロシージャの場合、そのプロシージャに相当する関数を含む C# クラスが必要なインポート文と併せて生成されます。
- x がモジュールの場合、CSharpDetails ヘルプページで説明のある通り C# クラスが生成されます。
パラメータ cgopts は、CodeGenerationOptions に説明している通り CodeGeneration オプションをひとつまたは複数含んでいることがあります。
CodeGeneration パッケージが Maple コードを他言語に変換する方法についての詳細は、言語変換の詳細 をご覧ください。特に C# への変換についての詳細は、CSharpDetails をご覧ください。
互換性
CodeGeneration[CSharp] コマンドは Maple 15 より導入されました。
Maple 15 の変更点についての詳細は、Maple 15 の更新情報 をご覧ください。
例
以下の例で使用しているオプションについては、CodeGenerationOptions をご覧ください。
with(CodeGeneration):
単純表現を変換し、変換先言語で名前 に代入。
CSharp(x+y*z-2*x*z, resultname="w");
w = x + y * z - 2 * x * z;
リストを変換し、変換先言語で名前 の配列に代入。
CSharp([[x, 2*y], [5, z]], resultname="w");
w[0,0] = x; w[0,1] = 2 * y; w[1,0] = 5; w[1,1] = z;
計算シーケンスを変換。ただし、まずは入力を最適化。
cs := [s=1.0+x, t=ln(s)*exp(-x), r=exp(-x)+x*t]:
CSharp(cs, optimize);
s = 0.10e1 + x; t1 = Math.Log(s); t2 = Math.Exp(-x); t = t1 * t2; r = t2 + x * t;
が浮動小数で、 が整数と宣言。結果は文字列として返す。
s := CSharp(x+y+1, declare=[x::float, y::integer], output=string);
プロシージャを変換。型が指定されていない変数は全て integer とみなします。
f := proc(x, y, z) return x*y-y*z+x*z; end proc:
CSharp(f, defaulttype=integer);
public class CodeGenerationClass { public static System.Int32 f (System.Int32 x, System.Int32 y, System.Int32 z) { return x * y - y * z + x * z; } }
暗黙リターンを含むプロシージャを変換。戻り値を記録するために新しい変数が作られます。
f := proc(n) local x, i; x := 0.0; for i to n do x := x + i; end do; end proc:
CSharp(f);
public class CodeGenerationClass { public static System.Double f (System.Int32 n) { System.Double x; System.Int32 i; System.Double cgret; x = 0.0e0; for (i = 1; i <= n; i++) { x = x + (System.Double) i; cgret = x; } return cgret; } }
パラメータとして配列を取るプロシージャを変換。CSharp 配列のインデックスが 0 から始まるように、インデックスの数字が振り直されることに注意してください。
f := proc(x::Array(numeric, 5..7)) return x[5]+x[6]+x[7]; end proc:
public class CodeGenerationClass { public static System.Double f (System.Double[] x) { return x[0] + x[1] + x[2]; } }
モジュールを変換。
m := module() export p; local q; p := proc(x,y) if y>0 then trunc(x); else ceil(x); end if; end proc: q := proc(x) sin(x)^2; end proc: end module:
CSharp(m, resultname=t0);
using System; public class m { public static System.Int32 p (System.Double x, System.Int32 y) { if (0 < y) return (System.Int32)(x); else return (System.Int32)Math.Ceiling(x); } private static System.Double q (System.Double x) { return Math.Pow(Math.Sin(x), 0.2e1); } }
双曲線三角関数の線形結合を変換。
CSharp(2*cosh(x)-7*tanh(x));
cg0 = 0.2e1 * (Math.Exp(x) + Math.Exp((-0.1e1) * x)) / 0.2e1 - 0.7e1 * (Math.Exp(0.2e1 * x) - 0.1e1) / (Math.Exp(0.2e1 * x) + 0.1e1);
戻り値がなく、printf 文を含むプロシージャを変換。
f := proc(a::integer, p::integer) printf("The integer remainder of %d divided by %d is: %d\n", a, p, irem(a, p)); end proc:
using System; public class CodeGenerationClass { public static void f (System.Int32 a, System.Int32 p) { Console.WriteLine("The integer remainder of " + a + " divided by " + p + " is: " + a % p); } }
参照
CodeGeneration, CodeGenerationOptions, CSharpDetails, TranslationDetails
Download Help Document