How can I modify values of eye
Show older comments
I am trying to code huckles determinant, and was able to get the matrix for cyclic hydrocarbons and lineal ones, however, I have not been able to do it for chains of carbons with substituents like (carbon 1, has 1 ch3 substituent)... I tried changing the values specifically of the eye matrix, but it just keeps on adding a two for every value instead of only the 6th and 7th value of a 5 carbon chain. I tried using A(r,c) = 2.... sorry the inputs are in spanish... Please help if you can!
disp('Hueckels determinante ')
pause(1)
s = menu('Hidrocarburos','Ciclicos', 'Lineales', 'Substituidos');
c = input('Cantidad de carbonos del Hidrobarburo ');
switch s
case 1
A = -eye(c);
A(1,c) = 1;
A(c,1) = 1;
v = ones(1,c-1);
A(logical(diag(v,1)))= 1;
A(logical(diag(v,-1)))= 1
case 2
A = -eye(c);
v = ones(1,c-1);
A(logical(diag(v,1)))= 1;
A(logical(diag(v,-1)))= 1
case 3
d = input('Cantidad de susbtituyentes ' );
for K = 1:d
disp(['En cual carbono: ' ,num2str(K),])
m(K) = input(' ');
end
c = input('Cantidad de carbonos del Hidrobarburo ');
x = ((c+1):(c+d));
A = -eye(c);
v = ones(1,c-1);
A(logical(diag(v,1)))= 1;
A(logical(diag(v,-1)))= 1
A(m,x) = 2
A(x,m) = 2
end
6 Comments
Jan
on 21 Jul 2018
The technical terms "huckles determinant", "cyclic hydrocarbons", etc. are confusing only. Remember that Matlab does not know its meaning and in consequence these details are not required for a working solution also. Prefer to concentrate on the problem: Which part of the code does not work as expected? Which result do you get and what do you want instead? An explicit example would be useful.
Stephen23
on 22 Jul 2018
case 3
d = input('Cantidad de susbtituyentes ' );
for K = 1:d
disp(['En cual carbono: ' ,num2str(K),])
m(K) = input(' ');
end
c = input('Cantidad de carbonos del Hidrobarburo ');
x = ((c+1):(c+d));
A = -eye(c);
v = ones(1,c-1);
A(logical(diag(v,1)))= 1;
A(logical(diag(v,-1)))= 1
A(m,x) = 1
A(x,m) = 1
My problem is with this case specifically, I have my matrix -eye(c+d) which is the amount in total I want to input in the end, so I try to modify the diagonal (A(logical(diag(v,1)))= 1) to only change the values until c, which takes it from v = ones(1,c-1) here, what gives me is a matrix that misplaces the (1) ones to other places...... Also, I want to modify the -eye matrix introducing specific values like changing a zero in colunm 1 and row 6 to 1, that dependent on the input (d) and the for loop (m). so it should give me something like this:

Jhanna Ramirez Medina
on 22 Jul 2018
Jan
on 23 Jul 2018
Please post the code and the complete error message. I still do not understand, what the problem is.
The screenshot is not really clear due to the "-x".
Guillaume
on 23 Jul 2018
@Jhanna, To make it easier to understand what you, give us (using valid matlab syntax) and example of input and the desired output from that.
Jhanna Ramirez Medina
on 23 Jul 2018
Answers (1)
Jhanna Ramirez Medina
on 23 Jul 2018
0 votes
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!