- Function Handle Expectations: The eigs function expects afun to be a function handle that accepts a vector and returns a vector of the same size. Your current setup applies the transformation to a matrix, which isn't compatible with eigs.
- Matrix to Vector Conversion: Since eigs works with vectors, you need to reshape the input matrix into a vector, apply the transformation, and then reshape the result back into a vector.
tformarray handle as function parameter
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am trying to find the largest eigenvalues of some linear transforms, and thought that I could use eigs(afun,...) for the purpose, with 'afun' being a handle to my linear transform function.
The code is inserted below, including a similar operation using imtransform, which works fine.
N = 10;
x = eye(N);
% Compose transform:
T1 = [1 0 -(N+1)/2; 0 1 -(N+1)/2; 0 0 1];
T2 = [0 1 0; -1 0 0; 0 0 1];
T3 = [1 0 (N+1)/2; 0 1 (N+1)/2; 0 0 1];
tf = T3*T2*T1
T = maketform('affine',tf');
R = makeresampler('nearest','fill');
im_1 = imtransform(x,T,R); % test
fwd_1 = @(x) imtransform(x,T,R);
im_2 = tformarray(x,T,R,[1 2],[1 2], [N N] ,[],0); % test
fwd_2 = @(x) tformarray(x,T, R,[1 2],[1 2],[N N] ,[],0);
[v1,d1] = eigs(fwd_1,10);
[v2,d2] = eigs(fwd_2,10);
The last code-line generates the error (Matlab v 7.6.0.324, Windows XP, 32 bit):
----------------------- ??? Subscripted assignment dimension mismatch.
Error in ==> eigs at 249 workd(:,cols(2)) = Amtimes(workd(:,cols(1)));
Error in ==> eigs_test at 27 [v2,d2] = eigs(fwd_2,10); -------------------------
Is it a bug in eigs() or are my input parameters to tformarray() or eigs() wrong?
Thanks,
Esben
0 commentaires
Réponses (1)
arushi
le 21 Août 2024
Hi Esben,
The error you're encountering is likely due to a mismatch in dimensions when using the eigs function with a function handle. The eigs function expects the function handle to represent a linear operator that can be applied to a vector, returning another vector of the same size. In your case, the function handle fwd_1 or fwd_2 should apply the transform to a vector, not a matrix.
Hope this helps.
0 commentaires
Voir également
Catégories
En savoir plus sur Special Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!