Lumerical Script Language

Lumerical Script Language

一、基本语法

1.1 运算符

All operators and commands can be found in Scripting Language – Ansys Optics

几个重点运算符
1. ? 用于打印/输出

? (print, display)

SyntaxDescription
?command;Displays the output of the command on the screen This function does not return any data.
?(5+5);
result: 
10 

?"file_"+"name_"+num2str(1);
file_name_1

?1:2001;
matrices of length greater than 2000 are not displayed to the output

?num2str(1:2001)
1
2
3
⋮
2000
2001
2. : 用于表示数组

: (array operator, colon)

syntaxDescription
x = 2 : 10;x will be an array of numbers that start at 2 and increase by 1 for each consecutive number. The last entry will be <= 10. x will equal 2,3,…,9,10.
x = 6 : -1.5 : 2;x will be the array were the first element is 6, and consecutive elements decrease by 1.5. All elements will be >=2. In this example, the array will be [6, 4.5, 3].
B=A(:, 2)B will be the array containing all the elements from the second dimension of A.
a=l:5;     # a will be vector (1, 2, 3, 4, 5)
?b=a(4:-1:2);  # b will be vector (4, 3, 2) 

a=[1,2,3;4,5,6]; 
?b=a(:, 1); # b will be vector (1, 4)
3. ^ 用于表示指数

^ (exponent, power, caret)

SyntaxDescription
y = x^3;x cubed.
x=1:3;
y=2:4;
?z=x^y;
result: 
1  
8  
81   

NOTE: In expression A^B, if B is complex, the phase of A is evaluated from − π -\pi π to π \pi π.

4. % 用于表示带空格的变量名
CommandDescription
%variable with space%To create a variable name that contains spaces, such as “variable with space”, put a percentage sign before and after the variable name.
%variable with space%=2;
?%variable with space%*3;
result: 
6  

%x span% = get("x span");
?%x span% * 1e6;  # x span in um
result:
4.8  
5. # 注释

# (comment, sharp, hashtag, pound)

SyntaxDescription
x=1; # set x to 1Anything after the # character is ignored.
?"this string contains a # symbol";
6. . 从数据集中获取参数和属性

. (dataset dot)

SyntaxDescription
result = A.result;Retrieves the parameter or attribute “result” from the existing dataset A. The result is a scalar matrix.
E = getresult("profile","E");
f = E.getparameter("f");  # the parameter f
Ex = E.getattribute("Ex"); # the x component of the electric field
E2 = E.getattribute("E2"); # the electric field intensity, note that this only works if E is a vector

E = getresult("profile","E");
f = E.f;  # the parameter f
Ex = E.Ex; # the x component of the electric field
E2 = E.E2; # the electric field intensity, note that this only works if E is a vector
7. almostequal 用于浮点数判断相等
SyntaxDescription
out = almostequal(A, B);Returns 1 if |A - B| is less than or equal to |A + B|/2*1e-15. Returns 0 otherwise.
out = almostequal(A, B, relative diff);Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff. Returns 0 otherwise.
out = almostequal(A, B, relative diff, absolute diff);Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff or if |A - B| is less than or equal to absolute diff. Returns 0 otherwise.
A=[1,2];
B=[1,1];
?almostequal(A,B);
result: 
1 0 
?almostequal(A,B,0.01,2);
result: 
1 1 
 
?almostequal(1,2,1);
result: 
1   
8. [] 用于创建数组

[] (specify matrix element, square bracket)

CommandDescription
x = [u11,…,u1N; u21,…,u2N; uM1,…,uMN]Create an N by M matrix. Columns are separated with semicolons. Elements in a row are separated with commas. The entries can either be scalars or matrices of compatible dimension.
?x=[1,2;3,4;5,6];
result: 
1 2 
3 4 
5 6
?x(1:3,1);
result: 
1 
3 
5   

a=matrix(2,2,2); 
a(1,1)=1;
a(2,2)=2;
b=a+1;
?c=[a,b];
result(i,j,1):
1 0 2 1 
0 2 1 3 
result(i,j,2):
0 0 1 1 
0 0 1 1 

1.2 分支

if
SyntaxDescription
if(x < 5) { y = x^2; }Simple if statement on one line.
if(x < 5) {y = x^2;}Multi-line if statement
if(x < 5) {y = x^2;} else {y = x^3;}If else statement.
if(x < 5) {if(x > 0) {y = x^2;}} else {y = x^3;}Nested if statement with else.
if(x < 5) {y = x^2;} else if ( x > 10 ) {y = 2*x;}Chained if else if statement.
clear;
a=1;
b=2;
d=3;
if((a==1)|(b==2)&(d==3)){
	?"correct";
}
else{?"not correct";}
try
SyntaxDescription
try {Command1;Command2;…}Runs the block of commands. If an error occurs, the error message is displayed and the script continues.
try {Command1;Command2:…} catch(errMsg);Runs the block of commands. If an error occurs, the error message is stored in the variable “errMsg” and the script continues.
a=1;
try {
	?C;
}
?a;
Error: prompt line 3: C is not a valid function or variable name
Result:
1

a=1;
try {
	?C;
} catch(errMsg);
?a;
?errMsg;
Result:
1
Error: prompt line 3, C is not a valid function or variable name

1.3 循环

for
SyntaxDescription
for(x=1:100) { ?x; }Single argument for loop. The loop will be sequentially executed for each value of x.
for(x=1; x<= 100; x=x+1) {?x;}Three argument for loop.x=1 at the start of the loop. The loop continues while x <=100 and sets x=x+1 at each pass.
x=1;for(0; x<10; 0) {?x;x=x+1;}This is equivalent to a while loop that will execute
a=1:2:10;
for(x=a) { 
	?x; 
} 

for(i=1:100) { 
	for(j=1:100) { 
		x(i,j) = i^2+j; 
		?x; 
	} 
} 

run;
mNames = splitstring(getresult,endl);

for (i=1:length(mNames)) {
	if (haveresult(mNames{i},"E")) {
		E=getresult(mNames{i},"E");   # get a result from that monitor
	} else {
		E = mNames{i} + " did not contain the specified data.";
	}
	savedata(mNames{i},E);     # save data to file
}

# implementation of a while loop in languages that support while loops
x=1;
while(x<10) {
	?x;
	x=x+1;
}
# equivalent implementation of a while loop in Lumerical script language
x=1;
for(0; x<10; 0) {
	?x;
	x=x+1;
}
  • 24
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: script language =javascript 是一种用于编写JavaScript脚本的标记语言。JavaScript是一种广泛使用的编程语言,用于在网页上添加交互性和动态效果。在HTML文档中,可以使用<script>标签来嵌入JavaScript代码,其中language属性指定了使用的脚本语言。在现代Web开发中,通常使用更简洁的方式来嵌入JavaScript代码,如使用<script>标签的type属性来指定脚本类型,或直接将JavaScript代码写入HTML文档中的<script>标签中。 ### 回答2: JavaScript是一种脚本语言,用于在网页中增加交互性和动态性。它被广泛用于网页开发和设计中,可以通过在HTML文档中嵌入代码来实现各种功能。 JavaScript具有许多特点和优势。首先,它是一种解释性语言,可以直接在网页中运行,无需编译。这使得JavaScript非常适合开发和调试网页交互功能。其次,JavaScript是一种面向对象的语言,提供强大的面向对象编程能力,使开发人员可以更灵活地组织和管理代码。此外,JavaScript还有一系列内置的函数和方法,能够方便地处理文本、数学计算、日期和时间等操作。 在网页开发中,JavaScript可以用于实现很多不同的功能。例如,通过JavaScript可以对用户输入进行验证,确保输入的数据符合要求。它还可以动态地改变网页的内容和样式,实现一些动画效果和页面的实时更新。此外,还可以通过JavaScript与服务器进行通信,实现异步加载数据和动态更新页面的功能。 JavaScript已经成为网页开发中不可或缺的一部分,广泛应用于前端开发、移动应用开发和游戏开发等领域。同时,它也是学习和掌握的一门重要编程语言,掌握JavaScript的知识可以帮助开发者更好地构建交互性和动态性的网页。 ### 回答3: JavaScript是一种脚本语言,广泛用于网页开发中的动态交互。它是一种高级编程语言,易于学习和使用。JavaScript能够直接嵌入在HTML文档中,并在网页加载时自动执行。 JavaScript具有很多特性和功能。首先,它能够处理网页的事件,例如鼠标点击、键盘敲击等,以及处理响应与这些事件相关的操作。这使得网页可以根据用户的操作实时更新和改变。 其次,JavaScript还具有动态修改网页内容和样式的能力。通过JavaScript,可以通过操作DOM元素(文档对象模型)来实现对网页的内容进行增加、删除或修改,还可以改变元素的样式和属性。 此外,JavaScript还可以进行数据验证和用户输入的处理。它可以对用户输入的数据进行验证,确保输入符合预期,提高网页的安全性,并对用户输入进行一些必要的处理,例如表单的提交和数据的处理。 JavaScript也支持面向对象编程,能够通过创建对象和调用方法来组织和管理代码,提高代码可重用性和可维护性。 最后,JavaScript还有丰富的第三方库和框架,例如jQuery、React、Vue等,可以帮助开发者更快速地构建复杂的网页和应用程序。 总结来说,JavaScript是一种功能强大的脚本语言,具有丰富的特性和功能,适用于网页开发中涉及动态交互的方方面面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值