Newton Raphson equation trig functions
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Derek Reitnouer
le 31 Août 2018
Commenté : Muhammad Qasim
le 5 Juil 2021
Trying to calculate root to an equation using newton raphson. also need to tabulate the results. the table isn't showing any info though.
clc
clear all
syms x
T = []; % Define table
x0 = .1; % Define Initial Value
i = 1; % Define Counter
N = 10; % Define max number of iterations
% Define Variables
S = 5281.716;
L = 5280;
f(x) = x - (S/L) * sin(x); % Define Function
df = diff(f); % Differential Function
while i <= N
x = x0 - (f(x0)/df(x0)); % Newton-Raphson Equation
if abs(x-x0) <= 10^-8
return
end
R = S/(2*x0); % Radius
d = R*(1-cos(x0)); % Distance d
T = [T; i x0 R d];
i = i + 1; % Increase Counter
x0 = x; % Update value of x0
vpa(x0) % Decimal
end
T = table(Iteration, Theta, Radius, d);
5 commentaires
Réponse acceptée
James Tursa
le 31 Août 2018
Instead of doing all of this as symbolic, it would probably have been simpler to use function handles and work in double. That being said, maybe just convert your stuff to double as you accumulate it:
T = [T; double([i x0 R d])];
Then you can use T to plot stuff directly.
Also, it would make more programming sense to change that "return" statement to a "break" statement.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox 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!