%
% R1 = 67.32 Ohm
% R2 = 32.68 Ohm
%

% Head start - Init
clear
home
close all

% this load command is needed for octave
% if you use matlab you don't need that
pkg load symbolic
% Head end

% Prog start
syms R1 Ir Ip U
SR1 = solve([R1 * (( U / Ir) - R1) * Ip * Ir] == U^2, [R1])

U = 220; % voltage
Ip = 10; % current in parallel connection
Ir = 2.2; % current in series connection

% Matlab solution
R1 =  (U * (Ip * (Ip - 4 * Ir))^(1/2) + Ip * U)/(2 * Ip * Ir)
R2 = ((U * (Ip * (Ip - 4 * Ir))^(1/2) - Ip * U)/(2 * Ip * Ir)) * (-1)
%

% Octave solution
R1 = U*( (1 / (2 * Ir)) + ( sqrt(Ip * (Ip - 4 * Ir)) / (2 * Ip * Ir)) )
R2 = U*( (1 / (2 * Ir)) - ( sqrt(Ip * (Ip - 4 * Ir)) / (2 * Ip * Ir)) )

% eliminate the square root
R1 = U*( (1 / (2 * Ir)) + ( (Ip * (Ip - 4 * Ir))^(1/2) / (2 * Ip * Ir)) )
R2 = U*( (1 / (2 * Ir)) - ( (Ip * (Ip - 4 * Ir))^(1/2) / (2 * Ip * Ir)) )
%

% Prog end
