酷代码 AI
菜单
全部AI  /  热门  /  AI问答
服务商

用octave 1. 求函数f(x)=x^2/3(x^2−8)的极值。 2.用多种数值方法计算定积分∫₀^π/4 1/(1−sin⁡x)dx,并与精确值√2进行比较,观察不同方法相应的误差。 3.用数值方法求解下列微分方程,用不同颜色和线型将y和y'画在同一图形窗口里: y"−y′+y=3cos⁡t 初始时间:t₀=0;终止时间:tғ=2π;初始条件:y|ₜ₌₀ =0,y'|ₜ₌₀ =0

以下是使用 Octave 解决您提出的问题的代码和步骤: ```octave % 问题 1 function f = myFunction(x) f = x.^2/3.*(x.^2 - 8); endfunction [xmin, fmin] = fminsearch(@myFunction, 0); [xmax, fmax] = fminsearch(-@myFunction, 0); disp(['极小值为:', num2str(fmin), ',在 x = ', num2str(xmin)]) disp(['极大值为:', num2str(fmax), ',在 x = ', num2str(xmax)]) % 问题 2 function y = myIntegrand(x) y = 1/(1 - sin(x)); endfunction exact_value = sqrt(2); % 梯形法则 trapz_result = trapz(0:0.01:pi/4, myIntegrand(0:0.01:pi/4)); trapz_error = abs(exact_value - trapz_result); disp(['梯形法则结果:', num2str(trapz_result), ',误差:', num2str(trapz_error)]) % 辛普森法则 simpson_result = quad(@myIntegrand, 0, pi/4); simpson_error = abs(exact_value - simpson_result); disp(['辛普森法则结果:', num2str(simpson_result), ',误差:', num2str(simpson_error)]) % 问题 3 function dy = myODE(t, y) dy = [y(2); 3*cos(t) - y(2) + y(1)]; endfunction [t, y] = ode45(@myODE, [0, 2*pi], [0, 0]); plot(t, y(:, 1), 'r-', t, y(:, 2), 'b--') legend('y', 'y''') ``` 您需要在 Octave 环境中运行上述代码来获得具体的结果。 [2025-04-01 19:26:36 | AI问答 | 470点数解答]

相关提问