Startpage >> Main >> SingleArraysMATLAB-likeNotation

Single Arrays MATLAB-like Notation

Single arrays with MATLAB-like operations and : notation

download example: singlearrays2.edp or return to Matrices and Arrays

cout<<"MATLAB like operations...notation sets values"<<endl;
int[int] tt(0:9),t1(10),t2(0:2:9);
cout<<"tt(0:9) set the values tt(0)=0,tt(1)=1,... "<<tt<<endl;
cout<<"t1(10) does not set values t1(0),t1(1),... "<<t1<<endl;
cout<<"t2(0:2:9) sets values t2(0)=0,t2(1)=2,t2(2)=4,... "<<t2<<endl;
cout<<"t2(3)= 6 "<<t2[3]<<endl;
cout<<"Size of t2(0:2:9) is "<<t2.n<<endl;
int N=5; 
real[int] a(N),b(N),c(N),d(N); 
a =1; 
a(0:4:2) = 2; 
a(3:4) = 4; 
cout <<" a = " << a << endl; 
b = a+a; 
cout <<" b = a+a : b= " << b << endl; 
d=b+a; 
cout <<" d=b+a : d= " << d << endl; 
b += a; 
cout <<" b += a : b= " << b << endl; 
d=b+2*a; 
cout <<" d=b+2*a : d= " << d << endl; 
b += 2*a; 
cout <<" b += 2*a : b= " << b << endl; 
d=b*.5; 
cout <<" d=b*0.5 : d= " << d << endl; 
b /= 2; 
cout <<" b /= 2 : b= " << b << endl; 
cout <<"  b= " << b << endl;
cout <<"  a= " << a << endl;
b.*=a; 
cout << "b.*=a componentwise product of b and a; b = " << b << endl; 
cout <<"  b= " << b << endl;
cout <<"  a= " << a << endl;
b./=a; 
cout << "b./=a; componentwise division of b and a; b = " << b << endl; 
cout <<"  b= " << b << endl;
cout <<"  a= " << a << endl;
c = a+b; 
cout << " c =a+b : c= " << c << endl; 
c = 2*a+4*b; 
cout << " c =2*a+4*b : c= " << c << endl; 
c = a+4*b; 
cout << "  c = a+4*b : c= "<<c<<endl; 
c = -a+4*b; 
cout << "  c = -a+4*b : c= "<<c<<endl;
c = -a-4*b; 
cout << "  c = -a-4*b : c= "<<c<<endl;
c = -a-b; 
cout << "  c = -a-b : c= "<<c<<endl;
cout <<"  a= " << a << endl;
cout <<"  b= " << b << endl;
c = a .* b; 
cout<<"c=a.*b componentwise product a and b: c = "<<c<<endl;
c = a ./ b; 
cout<<"c=a./b componentwise division a and b: c = "<<c<<endl;
c = 2 * b; 
cout << " c = 2*b : c = "<<c<<endl;  
c= b*2; 
cout << " c =b*2 : c = "<<c<<endl; 
//
// c=a/2 o c=a./2 does not exist.
//

return to Matrices and Arrays

Page last modified on April 03, 2014, at 01:02 PM