Divide by zero with subs
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
When I try to execute the code below it gives me the error "Error in MuPAD command: Division by zero. [_power]". The problem is because the vector w_vec has a zero at position 5001. I have tried many approaches: inline if (according to some article I found), function to test the vector values, index vector, and some others. The problem still occurs.
The only way I've found was to change the w_vec(5001) to 1 before the problematic line and then to zero right after. Although solving the problem, it seems very strange to do like that. Is there any other solution to this problem?
This code does not belong to me. I've found this code trying to understand how Fourier Transform works.
Thanks!!!
syms t w
tau = 1;
rect_sym = heaviside(t+tau/2)-heaviside(t-tau/2);
fourier_rect_sym = fourier(rect_sym);
t_vec = -3:0.01:3;
rect_t = subs(rect_sym, t, t_vec);
w_vec = -50:0.01:50;
fourier_rect_w = subs(fourier_rect_sym, w, w_vec);
1 commentaire
Christopher Creutzig
le 4 Avr 2016
Try using matlabFunction instead of subs:
syms t w
tau = 1;
rect_sym = heaviside(t+tau/2)-heaviside(t-tau/2);
fourier_rect_sym = fourier(rect_sym,t,w);
fourier_rect = matlabFunction(fourier_rect_sym);
t_vec = -3:0.01:3;
rect_t = fourier_rect(t_vec);
w_vec = -50:0.01:50;
fourier_rect_w = fourier_rect(w_vec);
Réponses (1)
Walter Roberson
le 25 Nov 2015
fourier_rect_w = arrayfun(@(W) limit(fourier_rect_sym,w,W), w_vec);
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!