Why MathNet Point3D components are ReadOnly? - mathnet-numerics

Does anyone knows why the Components X, Y and Z of a MathNet.Spatial.Euclidean.Ponit3D are readonly doubles?
Regards,
David

From what i understand from this link Point3D is a ValueType/Struct, not a reference type class.
Now because of this i suspect that you would have to re-assign the whole object instead of trying to modify its components separately. Think of it like ( loosely ) a primitive value

Related

Does MATLAB have any set-like datatype?

I am looking for a way to compare finite sequential data with non-deterministic ordering in MATLAB. Basically, what I want is an array, but without imposing an order on the contained elements. If I have the objects
a = [x y z];
and
b = [x z y];
I'd want isequal(a, b) to return true. With arrays, this is not the case. The easy fix would be to sort the entries before comparing them. Unfortunately, in my case the elements are complex objects which cannot easily be mapped to have an unambigious numerical relationship to each other. Another approach would be not to use isequal, but rather a custom comparison function which asserts matching lengths and then simply checks if each element from the first array is contained in the second one. However, in my case the arrays are non-trivially nested inside the structs I am trying to compare via isequal, and it would be quite complicated to write a custom comparison function for the encapsulating structs. Other than this ordering problem, the inbuilt isequal function covers all of my needs, as it correctly handles arbitrarily nested structs with arbitrary fields, so I would really like to avoid writing a complicated custom function for that.
Is there any datatype in MATLAB which allows for the described behavior? Or is there a way to easily build such a custom type? In Java, I could simply write a wrapper class with a custom implementation for the equals method, but there seems to be no such mechanism in MATLAB?
I've found a way to solve my problem elegantly. Contrary to my previously stated belief, MATLAB actually does allow for class-specific overriding of isequal.
classdef CustomType
properties
value
end
methods
function self = CustomType(value)
self.value = value;
end
function equal = isequal(self, other)
if not(isa(other, 'CustomType'))
equal = false;
return;
end
% implement custom comparison rules here
end
end
end
So, I can simply assign the fields in question like this and don't have to change anything else in my code:
a = Set([x y z]); % custom type
...
b = Set([x z y]);
...
isequal(a, b); % true
In my use case, I don't even need the uniqueness property of sets. So I only have to perform order-independent comparison and don't need to waste performance on ensuring unrequired properties. Furthermore, by using a dedicated type, I can differentiate explicitly between fields which have order (i.e. regular arrays) and those which don't, at the moment of assignment.
Another solution might be to overwrite the inbuilt isequal and make it apply custom comparison rules when its arguments are of specific type. However, this would slow down all comparisons in the whole program and make for bad encapsulation. I feel like using a custom type with an overriden isequal is the way to solve this kind of problem. But I still think that sets (and other types of commonly used containers) should be included in the basic repertoire of MATLAB.

MATLAB - automatically apply obj references in function

when working with objects in Matlab I constantly have to type
"obj.x, obj.y"
Is there a way to automatically set my matlab functions to apply the obj. reference, so I can just type x and y.
currently i must type as follows:
z = function(obj)
z=obj.x+obj.y
i would like to type
z = function(obj)
z=x+y
No. Sorry; this is just how Matlab works; object references are always explicit.

Plotting a function in an implicit formula

I want to sweep the variable Q from -.4 to +.4 and then plot the variable V for each individual value of Q.
0.188Q^2+.44*V^2*Q+.0221+V^4+(.2-1.05^2)*V^2=0
But I am not sure how to go about solving this problem, as I have never faced something like this before. Can someone please advice on how to code this?
This is job for ezplot!
As you have your function in implicit form, unless you write it in explicit form (i.e. y=..) you can not use plot. But you can use ezplot!
just do
ezplot('x.*0.188*x.^2+.44*y.^2*x+.0221+y.^4+(.2-1.05^2)*y^2',[-4 4])

How to convert type of a variable when using JuMP

I am using Julia/JuMP to implement an algorithm. In one part, I define a model with continues variables and solve the linear model. I do some other calculations based on which I add a couple constraints to the model, and then I want to solve the same problem but with integer variables. I could not use convert() function as it does not take variables.
I tried to define the variable again as integer, but the model did not seem to consider it! I provide a sample code here:
m = Model()
#defVar(m, 0 <= x <= 5)
#setObjective(m, Max, x)
#addConstraint(m, con, x <= 3.1)
solve(m)
println(getValue(x))
#defVar(m, 0 <= x <= 1, Bin)
solve(m)
println(getValue(x))
Would you please help me do this conversion?
The problem is that the second #variable(m, 0 <= x <= 1, Bin) actually creates a new variable in the model, but with the same name in Julia.
To change a variable from a continuous to a binary, you can do
setcategory(x, :Bin)
to change the variable bounds and class before calling solve again.
In newer versions of JuMP, you need to use a different function than setcategory. The methods you are looking for are:
set_binary Add binary constraint to variable.
unset_binary Remove binary constraint from variable.
set_integer Add integer constraint to variable.
unset_integer Remove integer constraint from variable.
The documentation on this can be found here.

automatically assign class type in matlab

I'd like to obtain a class type of a variable and use it as a function in Matlab.
For example, say x is of class uint8. I can obtain this info by classtype=class(x).
What I'd like is to use it on a different variable automatically, such as:
y=classstype(y)
where y is of type logical for example.
How can I accomplish that?
It sounds like you're trying to cast the value of y to a different class. To this end, you could try using Matlab's cast() function.
In your specific instance, you could try:
y = cast(y, class(x))
This should get the class of variable x and cast variable y to that class.
The function class() returns the string with a class name. You can use it further using the function eval() which deals with strings as an input.