第十四 算数运算

算数运算

rust 复制代码
use std::f64::consts::{PI, E};
fn main() {
    let x = 11;
    let y = 2;
    let z = -31;
    let r : f64 = 2.0;
    println!("{}", x + y); 
    println!("{}", x - y); 
    println!("{}", x * y); 
    println!("{}", x / y); 
    println!("{}", x % y); 
    println!("{}", z % x); 
    println!("{}", PI * r.powi(2));
    println!("{}", 4096_f64.log2());
    println!("{}", 4096_f64.log10());

    //高考真题: a = 0.1e^0.1 , b = 1/9 , c = -ln(0.9),求三者的大小关系
    //正确答案:c < a < b
    println!("{}", 0.1 * E.powf(0.1));
    println!("{}", 1.0_f64 / 9.0_f64);
    println!("{}", -(0.9_f64).ln());
    
}

三角函数,反三角函数

rust 复制代码
use std::f64::consts::PI;

fn main() {
    // 弧度
    let x: f64 = PI / 2.0;
    println!("{}", f64::sin(PI)); 
    println!("{}", x.sin()); 
    println!("{}", x.cos()); 
    println!("{}", x.tan());
    println!("{}", (PI / 4.0).tan());
    // 计算 30 度 (π/6 弧度) 的正弦值
    let angle_deg = 30.0_f64;
    // 转换为弧度
    let angle_rad = angle_deg.to_radians(); 
    let sin_val = angle_rad.sin();
    println!("sin(30°) = {}", sin_val);
    println!("sin(60°) = {}", 60.0_f64.to_radians().sin());

    // 验证 tan(x) 是否等于 sin(x) / cos(x)
    let x = 6.0_f64;
    let tan_direct = x.tan();
    let tan_computed = x.sin() / x.cos();
    assert_eq!(tan_direct, tan_computed);

    //勾三股四弦五,求勾所对应的角度是多少?
    //sin(x) = 3/5,求对应的角度x
    let x = 0.6_f64;
    let theta = x.asin();
    let theta_deg = theta * 180.0 / PI;
    println!("弧度 = {} ,角度 = {}", theta, theta_deg);
}

20以内所有阶乘

rust 复制代码
fn factorial_checked(n: u64) -> Option<u64> {
    (2..=n).try_fold(1u64, |acc: u64, x: u64| {
        let acc = acc.checked_mul(x)?;
        Some(acc)
    })
}

fn main() {
    // 使用示例
    for i in 2..=20 {
            match factorial_checked(i) {
                Some(result) => println!("{}! = {}", i, result),
                None => println!("计算溢出"),
            }
    }
}

例子

高考真题: a = 0.1e^0.1 , b = 1/9 , c = -ln(0.9),求三者的大小关系

正确答案:c < a < b

求证:

\\boldsymbol{-\\ln(1-x) \< x e\^x \< \\frac{x}{1-x},\\quad x\\to0\^+,\\;0\

分两段证明:\\boldsymbol{-\\ln(1-x)\、\\boldsymbol{xe\^x\<\\dfrac{x}{1-x}}。

一、先证右侧:\\boldsymbol{xe\^x \< \\dfrac{x}{1-x}\\ (0\

x\>0,两边同除以x等价于:

e\^x \< \\frac1{1-x}\\iff e\^x(1-x)\<1

设

F(x)=e\^x(1-x)-1,\\quad F(0)=e\^0\\cdot1-1=0

求导:

F'(x)=e\^x(1-x)-e\^x=-x e\^x\<0,\\quad x\>0

F(x)在x\>0严格递减\\Rightarrow F(x)\,即

e\^x(1-x)\<1\\Rightarrow e\^x\<\\frac1{1-x}\\Rightarrow xe\^x\<\\frac{x}{1-x}.

✅ 右半不等式成立。

二、再证左侧:\\boldsymbol{-\\ln(1-x)\

变形:

xe\^x+\\ln(1-x)\>0

构造

G(x)=xe\^x+\\ln(1-x),\\quad G(0)=0+\\ln1=0

求一阶导:

G'(x)=e\^x+xe\^x-\\frac1{1-x}=e\^x(1+x)-\\frac1{1-x}

G'(0)=1\\cdot1-1=0

再求二阶导:

G''(x)=e\^x(1+x)+e\^x-\\frac1{(1-x)\^2}=e\^x(x+2)-\\frac1{(1-x)\^2}

G''(0)=2-1=1\>0。

由**泰勒展开(x\\to0\^+)**辅助验证:

-\\ln(1-x)=x+\\frac{x\^2}{2}+\\frac{x\^3}{3}+\\frac{x\^4}{4}+\\cdots

xe\^x=x\\left(1+x+\\frac{x\^2}{2}+\\frac{x\^3}{6}+\\cdots\\right)=x+x\^2+\\frac{x\^3}{2}+\\frac{x\^4}{6}+\\cdots

逐项比较,故小正数x:-\\ln(1-x)\。

从导数单调性:G'(0)=0,G''(0)\>0\\Rightarrow x\\to0\^+ 时G'(x)\>0,G(x)\\nearrow \\Rightarrow G(x)\>G(0)=0,

xe\^x+\\ln(1-x)\>0\\iff -\\ln(1-x)\

✅ 左半不等式成立。

三、合并结论

\\boldsymbol{-\\ln(1-x) \< x e\^x \< \\frac{x}{1-x},\\quad x\\to0\^+,\\;0\

补充:三者等价无穷小( x \\to 0\^+ )

三者是**同阶等价无穷小**,只是从低到高:

-\\ln(1-x)\。

相关推荐
还卿一钵无情泪7 小时前
Unsloth 微调 构建自己的大模型 没有GPU也能微调
linux·开发语言·人工智能·python·大模型·nlp·unsloth
高山有多高7 小时前
【Linux笔记】IO模型
linux
不会就选b7 小时前
Linux之TCP理论<1>
linux·运维·服务器
小π军8 小时前
操作系统面试题
java·linux·服务器
用户033307413959 小时前
TypeScript using 与 AsyncDisposableStack:在真实服务端代码中协调多资源清理
前端
daisychey9 小时前
用 Playwright 做多平台内容分发,我踩过的 8 个坑
前端
Lsetea9 小时前
curl用IP测试HTTPS报证书不匹配:--resolve与Host头别混用
linux·https·ssl证书·openssl·curl
Hao2859 小时前
Windows11 下把 WSL2 Ubuntu 26.04 装到 D 盘完整
linux
Android系统攻城狮9 小时前
Linux Gstreamer深度解析之gst_audio_encoder_get_frame_samples_min调用流程与实战(六十)
linux·运维·服务器·音视频·gstreamer音视频·音视频进阶·gstreamer音视频进阶
IT_陈寒10 小时前
为什么你应该学习JavaScript?
前端·人工智能·后端