How can I modify values of eye

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

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.
Jhanna Ramirez Medina's "Answer" moved here:
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:
I tried offset to limit the diagonals (1) and (-1), but it shows an error saying index matrix doesn't match, or exceeds dimension.
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".
@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.
Alright, I will keep it in mind next time. Thank you!

Sign in to comment.

Answers (1)

Do no worry, I was able to make it work. Thanks though, I appreciate it!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!