Saturday, April 20, 2024

Menulis Source Code Latex

 \usepackage{verbatim} %menulis sourcecode
\usepackage{listings} %menulis sourcecode
\usepackage{xcolor}%menulis sourcecode
%---
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
%===
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}
\lstset{style=mystyle}
%---

\begin{lstlisting}[language=python, caption=Regresi Linier HP dan Kamera]
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression

df = pd.DataFrame([[8,7],[2,3],[6,7],[4,2],[7,8],[3,3]])
df.columns = ['x', 'y']

x_train = df['x'].values[:,np.newaxis]
y_train = df['y'].values

lm = LinearRegression()
lm.fit(x_train,y_train) # fase training

print('Coefficient : ' + str(lm.coef_))
print('Intercept : ' + str(lm.intercept_))

x_test = [[170],[171]] # data yang akan diprediksi
p = lm.predict(x_test) # fase prediksi
print(p) # hasil prediksi

# prepare plot
pb = lm.predict(x_train)
dfc = pd.DataFrame({'x': df['x'],'y':pb})

plt.scatter(df['x'],df['y'])
plt.plot(dfc['x'],dfc['y'],color='red',linewidth=1)
plt.xlabel('kamera')
plt.ylabel('harga')
plt.show()
\end{lstlisting}

Wednesday, January 10, 2024

Problem Set 2.5 - Chain Rule

 16. $ y= cos^3(\frac{x^2}{1 - x}) $

$ v= \frac{x^2}{1-x}, ~ u=cos \, v, ~ y = u^3 $

$\frac{dy}{dx} = \frac{dv}{dx}. \frac{du}{dv}. \frac{dy}{du}$

$ = (\frac{(1 - x)D_x(x^2) - (x^2) D_x(1 - x)}{(1 - x)^2}). (- sin \, v).(3u^2) $

$ = \frac{(1-x)(2x) -(x^2)(-1)}{(1 - x)^2}. sin(\frac{x^2}{1 -x}). (-3 cos^2 (\frac{x^2}{1 - x}))$

$ = \frac{-3(2x - x^2)}{(1 - x)^2}cos^2(\frac{x^2}{1-x}) sin(\frac{x^2}{1 -x }) $

Sunday, January 7, 2024

Problem Set 2.4 Derivatif Trigonometri

catatan :

$ \frac{d}{dx} sin x~= cos\, x$

$ D_x (cos x)~= - sin\, x$

$ \frac{d}{dx}tanx~=sec^2 x$

$D_x (cot\, x)~=-csc\, x $

$\frac{d}{dx} sec x~=sec\, x\, tan\, x$ 

--------

$ 6. ~y = csc\, x$

$ D_x(csc \, x) = D_x \frac{1}{sin x}$

$ = \frac{sin x\, D_x(1) - (1)\, D_x(sin x)}{sin^2 x}$

$ = \frac{0 - cos\, x}{sin^2 x}~=\frac{-1}{sin x}.\frac{cos\, x}{sin\, x}~= -csc\,x \,cot\, x$


$10.~y= \frac{sin x + cos x}{tan x} $ 

$\frac{d}{dx}(\frac{sin x + cos x}{tan x})$

$=\frac{tanx\, D_x (sin x+ cos x) - (sin x+ cos x)\, D_x (tan x)}{tan^2 x}$

 $= \frac{tanx(cosx-sinx)-(sinx+cosx)sec^2 x}{tan^2x}$

$= \frac{tanx(cosx-sinx)-(sinx+cosx)sec^2 x}{\frac{sin^2x}{cos^2x}}$ 

$ = [sin x - \frac{sin^2 x}{cos x} - \frac{sin x}{cos^2 x} - \frac{1}{cos x}]  : [\frac{sin^2 x}{cos^2 x}]$

$ = [sin x - \frac{sin^2 x}{cos x} - \frac{sin x}{cos^2 x} - \frac{1}{cos x}]  [\frac{cos^2 x}{sin^2 x}]$

$ =\frac{cos^2 x}{sin x} - cos x - \frac{1}{sin x} - \frac{cos x}{sin^2 x} $