Vector: Difference between revisions

Content added Content deleted
No edit summary
Line 12: Line 12:
The four operations to be implemented are:
The four operations to be implemented are:
* Vector <big><b> + </b></big> Vector addition
* Vector <big><b> + </b></big> Vector addition
* Vector <big><b> - </b></big> Vector subtraction
* Vector <big><b> - </b></big> Vlector subtraction
* Vector <big><b> * </b></big> scalar multiplication
* Vector <big><b> * </b></big> scalar multiplication
* Vector <big><b> / </b></big> scalar division
* Vector <big><b> / </b></big> scalar division
Line 972: Line 972:
(55, 77)
(55, 77)
(2.5, 3.5)</pre>
(2.5, 3.5)</pre>

=={{header|Maple}}==
Vector class:<lang Maple>module MyVector()
option object;
local value := Vector();

export ModuleApply::static := proc( )
Object( MyVector, _passed );
end proc;

export ModuleCopy::static := proc( mv::MyVector, proto::MyVector, v::Vector, $ )
mv:-value := v;
end proc;
export ModulePrint::static := proc(mv::MyVector, $ )
mv:-value;
end proc;

# operations:
export `+`::static := proc( v1::MyVector, v2::MyVector )
MyVector( v1:-value + v2:-value );
end proc;

export `*`::static := proc( v::MyVector, scalar_val::numeric)
MyVector( v:-value * scalar_val);
end proc;


end module:</lang>
<lang Maple>a := MyVector(<3|4>):
b := MyVector(<5|4>):

a + b;
a - b;
a * 5;
a / 5;</lang>
{{out}}
<pre>
[8, 8]
[-2, 0]
[15, 20]
[3/5, 4/5]
</pre>




=={{header|MiniScript}}==
=={{header|MiniScript}}==