Julia 高性能数值计算语言
简介:兼顾Python易用性与C级性能,用于气候仿真、量化、深度学习、工程建模
小白入门案例1:HelloWorld字符串输出
site = "doc.yiliancai.com"
println("欢迎学习Julia高性能科学计算 | $site")
小白入门案例2:循环累加1~100
sum_val = 0
for i in 1:100
sum_val += i
end
println("1到100总和:", sum_val)
基础实操案例3:矩阵基础运算
A = [1 2; 3 4]
B = [5 6; 7 8]
C = A + B
D = A * 2
println("矩阵相加:", C)
基础实操案例4:DataFrame表格筛选
using DataFrames
df = DataFrame(name = ["张三","李四"], age = [22,26])
adult = filter(row -> row.age > 24, df)
println(adult)
进阶项目案例5:Plots绘图正弦曲线
using Plots
x = 0:0.1:2π
y = sin.(x)
plot(x, y, title="Julia正弦函数图")
savefig("sin_plot.png")
进阶项目案例6:最小二乘线性回归
using LinearAlgebra
X = [1 1;2 1;3 1;4 1]
y = [2,4,6,8]
w = X \ y
println("回归系数:", w)
进阶项目案例7:CSV数据集读写统计
using DataFrames,CSV
data = DataFrame(value = randn(100))
CSV.write("data.csv", data)
df = CSV.read("data.csv", DataFrame)
println("均值:", mean(df.value))
企业精通案例8:多线程并行矩阵求逆
Threads.@threads for i in 1:100000
mat = rand(200,200)
inv(mat)
end
println("并行仿真完成")
企业精通案例9:Flux卷积神经网络图像分类
using Flux
model = Chain(Conv((3,3),1=>16,relu),MaxPool((2,2)),Flatten(),Dense(400,10))
x = rand(28,28,1,32)
out = model(x)
企业精通案例10:蒙特卡洛量化收益模拟
using Distributions
function monte(n::Int)
mu = 0.05;sigma=0.12
dist = Normal(mu,sigma)
res = rand(dist,n)
return mean(res),std(res)
end
avg,stdv = monte(1_000_000)
println("年化均值:$avg 波动:$stdv")
剩余6门语言(R/Mojo/MATLAB/Octave/TensorFlow DSL/PyTorch Script)统一10阶案例模板,仅替换对应数值/AI语法代码。