matlab这个题怎么做? matlab编程实例100篇

5344℃ JO

matlab这个题怎么做?matlab编程实例100篇

用matlab编写一个程序

展开全部

子函数:

function Y = subfun(t)

index = find(t < -5);

if size(index) ~= 0

x = t(1, index);

Y1 = (x.^3 + 5*x -10) / 6;

end

index = find((t>=-5)&(t<5));

if size(index) ~= 0

x = t(1, index);

Y2 = exp(x-1);

end

index = find(t >= 5);

if size(index) ~= 0

x = t(1, index);

Y3 = log10(7*x+4); %不确定你用的是以多少为底的对数,此处是10.

end

Y = [Y1 Y2 Y3];

调用函数:

x = -10: 0.05: 10;

y = subfun(x);

plot(x, y);

用MATLAB如何做下题:计算满足1+2+3+…+n<10000的最大正整数。

你好!

这个题竟然没人答,偶也在等答案……

如有疑问,请追问。

这道题用MATLAB怎么做,要截图过程,

下面这道题,求数学建模问题的最优解,用matlab怎么编程?

function love%主函数,也可以把这一段放在命令窗中运行.那样得把sub_f(x)函数存放在WORK中

clear;clc;

% x11,x12,x13,y22,y33,x22,x23 ->x(1),x(2),x(3),x(4),x(5),x(6),x(7)

maxf=inline('0.25*(x(1)+x(2)+x(3))*x(4)+(x(1)+x(2)+x(3))*(1-x(4))*0.2+(-x(2)+x(6)+x(7))*x(5)*0.23+(-x(2)+x(6)+x(7))*(1-x(5))*0.185','x') ;

%st. x(2)*80+x(3)*100+x(7)*85<=900

%-x(3)-(7)<=0

%x(3)+x(7)<=3.5

A=[0 80 100 0 0 0 85

0 0 -1 0 0 0 -1

0 0 1 0 0 0 1];

b=[900;0;3.5];

%0<=x(2)<=8.2

%0<=x(4)<=1

%0<=x(5)<=1

Lb=[-inf 0 -inf 0 0 -inf -inf];

Ub=[inf 8.2 inf 1 1 inf inf];

x0=0.5*ones(1,7);

Aeq=[];beq=[];

[x,f]=fmincon(maxf,x0,A,b,Aeq,beq,Lb,Ub,@sub_f);

x=x,f=-f

function [f feq]=sub_f(x)

f(1)=(x(1)+x(2)+x(3))*x(4)*1.4+(x(6)-x(2)+x(7))*x(5)*1.65-7.5;

f(2)=(x(1)+x(2)+x(3))*(x(4)*1.4+6.1)+(x(6)-x(2)+x(7))*(x(5)*1.65+7.35)-76.5;

feq(1)=0;feq(2)=0;

结果:

x =

1.0e+015 *

-4.4110 0.0000 -0.1376 0.0000 0.0000 -4.1338 0.1376

f =

4.8952e+018

也可以看我的博客文章的例子;

hi.baidu/jingtao1016/blog/item/22f34031a3cedbad5fdf0ee8.html

TAG: 实例