MATLAB求过程和答案。第一和三题优先解!

img


请尽量快一点发,多谢了

你好,可不可以把之前的给采纳了,答题好不容易啊,呜呜

% 第一题
f = @(x) x(1)^2+2*x(2)^2;
x0 = [0,-1];
options = optimoptions('fmincon','Algorithm','sqp');
[xmin, fmin] = fmincon(f, [1,0],[],[],[],[],[],[],@nonlcon);
fprintf('最小值处在(%f,%f),最小值为%f\n',xmin, fmin)
function [c, ceq] = nonlcon(x)
ceq=x(1)^2+x(2)^2-1;
c= [];
end

结果:
最小值处在(1.000000,0.000000),最小值为1.000000

% 第三题
odefun = @(t,y) [y(2);
0.01*y(2)^2-2*y(1)+sin(t);
];
y0 = [0;1];
[t,y] = ode45(odefun, [0,5], y0);
plot(t,y(:,1))
xlabel('t'); ylabel('y')

结果

img