relative error: Error using ==> mtimes
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello I am trying to get the relative error for sinx=sqrt(1-cos^2(x) and getting error with this matlab code:
clear
clc
x=logspace(-1,-10,10);
lhs=sin(x);
t=cos(x);
rhs=sqrt(1-cos(x)*cos(x));
abserr=abs(lhs-rhs);
Rel=abs((lhs-rhs)/lhs);
disp('x error rel.error')
disp('--------------------')
for i=1:10
disp(sprintf('%22.15e %22.15e %22.15e\n',x(i),abserr(i),Rel(i)))
end
end
??? Error using ==> mtimes Inner matrix dimensions must agree.
Error in ==> Q at 6 rhs=sqrt(1-cos(x)*cos(x));
any idea? thanks
0 commentaires
Réponse acceptée
Plus de réponses (1)
NH
le 16 Sep 2012
2 commentaires
Jan
le 17 Sep 2012
Modifié(e) : Jan
le 17 Sep 2012
- Please post a new thread for a new problem.
- Use the debugger to find the reasons for the size of Rel: Set a breakpoint in the line Rel=abs((lhs-rhs)/lhs) to find out, that exactly the same argument of matrix versus elementwise operations concerns the division also. Therefore you need ./ instead of / . Surprised?
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations 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!