%*******************************
% vectors_taylor_loop.m
% (c) Jaime V. Torres-Heredia, November 2025
%*******************************
clc; clear; close all;
%Defining the function * (mult)
function c = mult (a, b)
d = [0;0];
d(1) = a(1)*b(1)-a(2)*b(2);
d(2) = a(1)*b(2)+a(2)*b(1);
c = d;
endfunction
%Defining the function powv, n=>0
function c = powv (a, n)
switch(n)
case 0
c = [1;0];
return
case 1
c = a;
return
otherwise
e = a;
d=[0;0];
for i = 1:n-1
d = mult(e,a);
e = d;
endfor
c = d;
endswitch
endfunction
% --- Tracé des vecteurs ---
figure;
hold on; grid on; axis equal;
% Définir les limites des axes selon les vecteurs
maxX = max([2]) + 1;
maxY = max([2]) + 1;
axis([-1 maxX -1 maxY]);
% --- Définition des vecteurs ---
x = [0; (135/180)*pi]; % Premier valeur de la variable x (colonne)
s=[0;0];
for k = 0:10
%Coefficient
a = 1/factorial(k);
% --- Calcul des vecteurs-termes ---
t = a*powv(x,k);
% Tracer les vecteurs
quiver(s(1), s(2), t(1), t(2), 0, 'g', 'LineWidth', 2, 'DisplayName', 't');
% --- Calcul des sommes partielles ---
s = s+t;
endfor
% --- Définition des vecteurs ---
x = [0; (45/180)*pi]; % Premier valeur de la variable x (colonne)
s=[0;0];
for k = 0:10
%Coefficient
a = 1/factorial(k);
% --- Calcul des vecteurs-termes ---
t = a*powv(x,k);
% Tracer les vecteurs
quiver(s(1), s(2), t(1), t(2), 0, 'b', 'LineWidth', 2, 'DisplayName', 't');
% --- Calcul des sommes partielles ---
s = s+t;
endfor
%Cercle:
x = -1:0.01:1;
y = (1 - x .^ 2) .^ 0.5;
plot(x,y, "linewidth", 1, x,-y, "linewidth", 1);
% --- Calcul de la somme ---
%P = t0 + t1+t2+t3+t4+t5+t6;
% Légendes et axes
xlabel('Axe X');
ylabel('Axe Y');
title('Path of the polynomial');
legend show;
hold off;