Error using syms: division by zero

4 visualizzazioni (ultimi 30 giorni)
Wenjun
Wenjun il 30 Set 2015
Risposto: Walter Roberson il 30 Set 2015
Hi, here is my code:
clear
clc
a=0.13448;
syms x y;
fun=cos(a*(2*pi-acos(x/sqrt(x^2+y^2))));
zwj=diff(fun,x);
vpa(subs(subs(zwj,x,0.5),y,0.0))
I want to evaluate the derivative of the function at (0.5,0.0), and MATLAB gives me the error "Division by zero", but there shouldn't be a division by zero because I checked the analytical solution and no zero is in the denominator. Can someone give me some help? Thanks a lot

Risposte (1)

Walter Roberson
Walter Roberson il 30 Set 2015
To avoid the division by 0, you need to take the limit as y approaches 0, rather than just substituting 0.
If you examine your expression, you have arccos(x/sqrt(x^2+y^2)) . Differentiate with respect to x and you get something that has a denominator of sqrt(-x^2/(x^2+y^2)+1) . As y approaches 0, this approaches sqrt(-x^2/x^2 + 1) which approaches sqrt(-1+1) which is sqrt(0) which is 0. Therefore you would have a division by 0 if you consider the denominator in isolation. If you take the limit of the numerator and denominator, the numerator approaches 0 faster than the denominator approaches 0, so the limit approaches 0 -- but the instantaneous evaluation has a division by 0.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by