matlab - Calculating condition numbers for hilbert matrices -
okay, first off feel silly asking question since seems answer should simple can't figure out.
i have vector n:
n=[2:13]
i pass vector through elementwise returns vector calculated values:
condition=cond(hilb(n))
hilb(n) returns hilbert matrix dimension n. cond() calculates condition number, scalar value. currently, matlab returning condition single value using first value n, 2 instead of vector equal in length n.
i aware of using .* , sin.() , other commands compute things elementwise, can't find how function such this.
you can't pass vector hilb
that, unfortunately. should use loop, or simpler, arrayfun
:
condition = arrayfun(@(x) cond(hilb(x)), n)
note arrayfun
disguised loop, offers no performance benefit compared explicitly writing loop.
condition = zeros(1,numel(n)); ii = 1:numel(n) condition(ii) = cond(hilb(n(ii))); end
keep in mind hilb
ill-conditioned matrix, values high (cond(hilb(13))=8.3042e+19
. means resulting vector like: 1.0e+19* 0.0000 0.0000 ... 0.0017 8.3042
. if use format short e
, you'll see values of each individual element: 1.9281e+01 5.2406e+02 ... 8.3042e+19
.
Comments
Post a Comment