發表文章

陳柏安Python_Javascript網路執行_EXCEL_IRR二分法

圖片
  pmt = [0,0,0,0] #大帥哥程式設計586設定串列list pmt[0]=float(input('大帥哥躉繳金額: '))#float轉換成實數 float for nper in range(1,4): pmt[nper] = float(input('第'+str(nper)+'期回收: ')) def npv(rate): y = - pmt[0] for j in range(1,4): y = y + pmt[j]/(1+rate)**j return y a, b, gap, f = 0.0, 1.0, 9.0, 9.0 maxerror = 0.00000001 loopNumber = 1 while (gap > maxerror and abs(f) > maxerror and loopNumber < 100): loopNumber+=1 c = (a+b)/2; f = npv(c); if ( abs(f) > maxerror and gap > maxerror): if ( f>0 ): a = c else: b = c gap = b-a; print('大帥哥報酬率: ', c) print('大帥哥淨現值: ', f) print('大帥哥迴圈次數: ', loopNumber) 這學期學會網路程式語言JAVASCRIPT也學會人工智慧使用最多的PYTHON語言

陳柏安二分法求內部報酬率

圖片
躉繳 第1期 第2期 第3期 注意,包含首期躉繳的現金流量都大於0。 輸出: 報酬率: 淨現值: 迴圈次數: 陳柏安向劉任昌學習程式設計程式碼如下 <IFRAME WIDTH='100%'SRC='https://zh.wikipedia.org/zh-tw/%E4%BA%8C%E5%88%86%E6%B3%95_(%E6%95%B8%E5%AD%B8)'></IFRAME> head/head, body/body畫蛇添足,可拿掉,因為部落格架構已經下這些命令 <style> h1 {margin: 0;padding:20px 0;color:black;  text-shadow: 4px 4px 2px pink;} .Takming {border: 20px outset red;background-color: green;   color: white; text-align: center;} .pmt {width: 60pt;height: 20pt;background-color: coral;   color: white; text-align: right;} </style> <table border="1"> <tr align="center"><td>躉繳</td><td>第1期</td><td>第2期</td><td>第3期</td></tr> <tr><td><input class="pmt" type="number" /></td>    <td><input class="pmt" type="number" /></td>    <td><input class="pmt" type=...

陳柏安Javascript計算現值PresentValue和Python比較

圖片
利率y(rate) 期數n(nper) 金流m(pmt) 終值f(fv) 參考劉任昌金融市場講義https://drive.google.com/file/d/17z6UZgN5fC2XCO1L8_BQs57dgQXzbwou/view?usp=sharing 陳柏安學習HTML+CSS+JavaScript程式碼 body指令拿掉,因為沒有作用。部落格已經設定body 使用到的PYTHON指令 在Spyder開發環境編寫與執行Python 第一個python沒有使用函數def '''PYTHON註解三個單引號或雙引號前後''' r=float(input('利率: '))#input輸入是字串string n=float(input('期數: '))#要計算轉為實數real nubers m=float(input('收付: '))#浮點點float f=float(input('終值: ')) pv = f/(1+r)**n pv += m/r*(1 - 1/(1+r)**n) print('柯文哲計算現值', pv) 迴圈對照EXCEL填滿 '''PYTHON註解三個單引號或雙引號前後''' def pv(r,n,m,f):#自訂函數 p = m/r*(1 - 1/(1+r)**n)+f/(1+r)**n return p#執行函數的結果傳回去 n=float(input('期數: '))#要計算轉為實數real nubers m=float(input('收付: '))#浮點點float f=float(input('終值: ')) for i in range(1,10):#迴圈 r = i*0.01 x=pv(r,n,m,f) print('利率 ', r ,'價格 ', x)

Javascript的輸出字體.font與fillStyle與fillText

圖片
Javascript在網頁就可以執行不需要開啟Spyder sin執行 cos執行 橫軸 以上原始程式碼 <style>BUTTON{BORDER:GREEN 10PX SOLID;BORDER-RADIUS:30PX;FONT-SIZE:30PX;COLOR:BLUE;}</style> <h1>Javascript在網頁就可以執行不需要開啟Spyder</h1> <button onclick="LHsin()">sin執行</button> <button onclick="LHcos()">cos執行</button> <button onclick="xLine()">橫軸</button> <canvas height="400" id="my" style="background: black;" width="1200"></canvas> <script> var c = document.getElementById("my"); var cty = c.getContext("2d"); var g = 0.01;//增加一個廣域變數,用在下面的Math.sin(g*x); var h = 195; function LHsin() { var x = 0; var y = 200; cty.beginPath();  cty.lineWidth = 5;  cty.moveTo(x,y); while (x < 1000){   x = x + 1;   y = 200 - h * Math.sin(g*x);//數學Math正弦sin   cty.lineTo(x, y);   cty.strokeStyle = "yellow";   cty.stroke();    }; } function LHcos() { var x = 0; var y = 200-h...

三個Javascript函數sin,cos與canvas.font

Javascript在網頁就可以執行不需要開啟Spyder sin執行 cos執行 橫軸

陳柏安Javascript執行三角函數繪圖

圖片
Javascript在網頁就可以執行不需要開啟Spyder 陳柏安執行

陳柏安python繪製三角函數與powerpoint製作影片

圖片
python程式碼 from tkinter import * #或者import tkinter as tk import math tk = Tk() #建構視窗名為tk tk.geometry('1200x400')#視窗 寬1200像素 tk.title("劉任昌python tkinter三角函數") canvas = Canvas(tk, width=1200, height=400, bg='black') canvas.grid(row=0,column=0,padx=5,pady=5,columnspan=3) delay=10 # milliseconds, 1/1000秒 x1,y1,z1=0,200,10#python特徵,多變數=對等值 h=190 #上下範圍,相當於數學1到-1 def LH(): global x1, y1, z1#global全球,local當地 x2 = x1 + 1 #換到下個+1 y2=200 - h*math.sin(0.02*x2) z2=200 - h*math.cos(0.02*x2) L1=canvas.create_line(x1,y1,x2,y2,fill='red',width=10) L2=canvas.create_line(x1,z1,x2,z2,fill='yellow',width=10) if (x2 小於 1200): #沒有超過, 記得將 "小於" 改成運算 x1,y1,z1=x2,y2,z2#下一個起點是現在終點 canvas.after(delay,LH)#每隔delay執行 else: return LauHou() #執行LauHou老猴 tk.mainloop()