How to calculate bond length using ase? - ase

I know a function ase.Atoms.get_distance but I don't know how to use it.
Is there other functions I can use and how to use it ?

If you know the number of the atom object in your atoms object
you could probably do something like atoms[1].get_position and atoms[2].get_position and subtract the vectors.

If mol is an ase.Atoms object, use:
mol.get_distance(atom_index1, atom_index2)

Related

How to Matlab code combining to make it easier

Hello I wanted to reshape this code to make it easier.
sins=1/3*(sind(50)+sind(300)+sind(340));
coses=1/3*(cosd(50)+cosd(300)+cosd(340));
result=atand(sins/coses);
it will be more input like 50,300,340... so I wanted to like this
a=[50 300 340];
sins=1/3*(sind(a));
coses=1/3*(cosd(b));
result=atand(sins/coses);
but it doesnt work.
How can I make it ?
Thanks in advance.
In your first example, you sum all three values returned by sind, in your second code you don't sum them. Inputting a matrix, sind (like most mathematical functions in MATLAB) returns a matrix of the same size, applying the function to each element. Use sum to get the sum of a vector.
sins=1/3*(sum(sind(a)));

How to use find() method in simulink?

I have to translate the .m file to simulink but I don't have any idea about How to use find() method. The result of the find() method is variable vector, which is not allowed by the simulink. Does anybody can help? Thanks.
You can try using a matlab function block (or maybe a prelookup might work, depending on the application).
Use:
[index]=find(data,1)
The second parameter of find specifies how many indices you want to find. Now find outputs a constant length vector and can be used in simulink.
Perhaps you can do this with the Submatrix or Selector blocks. This answer may be helpful.

Matlab: Element by element selection without loops

I have one big matrix of for example 3000X300. And I need to select each element and do several calculations with it. I looked into using the array fun function but because the output of my program is not one value this is not possible.
It works fine now with the loops but it has to preform much faster, so i want to remove the for loop.
Maybe i'll try to be more specific: Each value of the big matrix has to give me an answer of 4 different matrices with the size of 4X6020..
So i don't know if this is possible making this vectorized...
Maybe somebody has other suggestions to make it faster?
greetings,
You can use arrayfun and set uniformoutput to false. See here.

Convert a 1X9 array to a 9X1

I want to substract two arrays in Matlab but they are of different sizes. When I try to substract them, it says the following:
??? Error using ==> minus
Matrix dimensions must agree
Does anyone has a clue?
Thanks in advance,
#Jens Björnhager is correct: the transpose() function will do what you want, which is to flip one of your input vectors from a row-vector to a column-vector.
Alternately, Use the ' operator. A' is shorthand for transpose(A).
Try the transpose() function to make the sizes match.

Dynamic variables matlab

How can I access to dynamic variables in Matlab? I search for similar question but I didn't find.
Example (simplified):
for i=1:1
aux3=(i-1)*50;
delay_64_264(1,i) = mean(delay_64_264_', num2str(aux3), ' (:,3)*100;
end
What I want to do is mean of column 3 from variable delay_64_264_0.
Anyone can help me?
Thank you very much
You can use eval().
But I recommend not doing this at all. Use a multidimensional array, rather than lots of variables with slightly different names.
To follow on from Oli's suggestions, see this piece of the MATLAB FAQ:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
which shows how to use structures and cell arrays as an alternative to eval.