matlab - Cannot use operator ^ on a vector value -
function[df] = getdiscountfactor(t,t,r,i) y=getyearfraction(t,t); a=r(i,1) df=1/((1+a)^y); end
this code, thing y cannot (1+a)^y operation because says it's vector, vector value r(i,1). when call in command line prints 0.03 , shows error
a = 0.0300 error using ^ inputs must scalar , square matrix. compute elementwise power, use power (.^) instead.
if use .^ operator problem solved df gets vector , need single number.
you've checked first input see it's scalar, presumably means other input, y
, not square matrix. if check y
too, see what's gone wrong.
and if not, matlab have function tells type matlab thinks object is? run on a
, on y
. or pedantic, run on 1+a
. should clear things up.
Comments
Post a Comment