2024年4月1日发(作者:邰乐心)
>> c*d
ans =
255
2.计算
(1)sin(60)
(2)e^3
(3)cos(3π/4)
>> sind(60)
ans =
0.8660
>> exp(3)
ans =
20.0855
>> cos(3*pi/4)
ans =
-0.7071
3.设u=2,v=3,计算:
(1)
(2)
(3)
>> u=2;
>> v=3;
>> 4*u*v/log(v)
ans =
21.8457
>> (exp(u)+v)^2/(v^2-u) ans =
15.4189
>> sqrt(u-3*v)/(u*v) ans =
0 + 0.4410i 4.计算如下表达式:
(1)
(2)
>> (3-5*i)*(4+2*i)
ans =
22.0000 -14.0000i >> sin(2-8*i)
1.3553e+003 +6.2026e+002i
4 3 0 -6
5 -34
>> vecB=[vec2 vec1]
vecB =
Columns 1 through 8
43 2 5 7 3 3 6253 3
Columns 9 through 16
4 3 0 -6
5 -34 4 5 2
Columns 17 through 24
8 4 7 2 64 2 57 2
Columns 25 through 26
45 7
>> small=vec<45
small =
Columns 1 through 17
1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1
Columns 18 through 26
1 1 0 1 1 1 1 1 1
>> vecS=vec(small)
vecS =
Columns 1 through 17
4 5 2 8 4 7 2 2 2 7 43 2 5 7 3 3 3
4 3 0 -6
5 -34
>> vec3R=vec(end:-3:1)
vec3R =
Columns 1 through 8
-34 3 6253 7 43 2 64 4
Column 9
5
>> vecN=find(vec==2|vec==4)
vecN =
1 3 5 7 9 11 15 22
>> [value]=vecN(find(mod(vecN,2)))
y_liner(i)=interp1(x,y,scalar_x(i),'liner');
y_spline(i)=interp1(x,y,scalar_x(i),'spline');
y_cubic(i)=interp1(x,y,scalar_x(i),'cubic');
end
subplot(2,2,1),plot(x,y,'*'),hold
on,plot(scalar_x,y_nearest),title('nearest'); %输出
subplot(2,2,2),plot(x,y,'*'),hold on,plot(scalar_x,y_liner),title('linear'); subplot(2,2,3),plot(x,y,'*'),hold
on,plot(scalar_x,y_spline),title('spline'); subplot(2,2,4),plot(x,y,'*'),hold on,plot(scalar_x,y_cubic),title('cubic');
2. 2. 求下列函数的解,并绘制图形。
(1) y=e x-x5,初始点为x=8.
(2) y=xsin(x)
>> y=@(x)exp(x)-x^5;
>> x=fzero(y,8)
x =
12.7132
>> fplot(y,[10,14]);
>> hold on
>> plot(x,y(x),'r*')
>>y=@(x)x*sin(x);
>> x=fzero(y,0)
x =
3.求下列函数的极值。
(1) z=x2-(y-1)2
(2) z=(x-y+1)2
>> z=@(x)x(1)^2-(x(2)-1)^2;
>> [x,fvalue]=fminsearch(z,[-1,1])
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
x =
1.0e+043 *
1.1138 1.2383
fvalue =
-2.9279e+085
>> z = @(x)(x(1)-x(2)+1)^2;
>> [x,fvalue]=fminsearch(z,[-1,1])
x =
>> ezplot(g,[-2,2])
7. 计算下列各式
(1)
(2),求
(3),求,,
(4),
>> limit(sym('(tan(x)-sin(x))/(1-cos(2*x))'))
ans =
>> y=sym('x^3-2*x^2+sin(x)')
y =
sin(x) - 2*x^2 + x^3
>> diff(y)
ans =
cos(x) - 4*x + 3*x^2
>> f=sym('x*y*log(x+y)')
f =
x*y*log(x + y)
>> diff(f,'x')
ans =
y*log(x + y) + (x*y)/(x + y)
>> diff(f,'y')
ans =
x*log(x + y) + (x*y)/(x + y)
>> y=sym('ln(1+t)')
y =
log(t + 1)
>> int(y)
ans =
(log(t + 1) - 1)*(t + 1)
>> int(y,0,27)
ans =
28*log(28) - 27
8.计算下列各式
(1)
(2)
2024年4月1日发(作者:邰乐心)
>> c*d
ans =
255
2.计算
(1)sin(60)
(2)e^3
(3)cos(3π/4)
>> sind(60)
ans =
0.8660
>> exp(3)
ans =
20.0855
>> cos(3*pi/4)
ans =
-0.7071
3.设u=2,v=3,计算:
(1)
(2)
(3)
>> u=2;
>> v=3;
>> 4*u*v/log(v)
ans =
21.8457
>> (exp(u)+v)^2/(v^2-u) ans =
15.4189
>> sqrt(u-3*v)/(u*v) ans =
0 + 0.4410i 4.计算如下表达式:
(1)
(2)
>> (3-5*i)*(4+2*i)
ans =
22.0000 -14.0000i >> sin(2-8*i)
1.3553e+003 +6.2026e+002i
4 3 0 -6
5 -34
>> vecB=[vec2 vec1]
vecB =
Columns 1 through 8
43 2 5 7 3 3 6253 3
Columns 9 through 16
4 3 0 -6
5 -34 4 5 2
Columns 17 through 24
8 4 7 2 64 2 57 2
Columns 25 through 26
45 7
>> small=vec<45
small =
Columns 1 through 17
1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1
Columns 18 through 26
1 1 0 1 1 1 1 1 1
>> vecS=vec(small)
vecS =
Columns 1 through 17
4 5 2 8 4 7 2 2 2 7 43 2 5 7 3 3 3
4 3 0 -6
5 -34
>> vec3R=vec(end:-3:1)
vec3R =
Columns 1 through 8
-34 3 6253 7 43 2 64 4
Column 9
5
>> vecN=find(vec==2|vec==4)
vecN =
1 3 5 7 9 11 15 22
>> [value]=vecN(find(mod(vecN,2)))
y_liner(i)=interp1(x,y,scalar_x(i),'liner');
y_spline(i)=interp1(x,y,scalar_x(i),'spline');
y_cubic(i)=interp1(x,y,scalar_x(i),'cubic');
end
subplot(2,2,1),plot(x,y,'*'),hold
on,plot(scalar_x,y_nearest),title('nearest'); %输出
subplot(2,2,2),plot(x,y,'*'),hold on,plot(scalar_x,y_liner),title('linear'); subplot(2,2,3),plot(x,y,'*'),hold
on,plot(scalar_x,y_spline),title('spline'); subplot(2,2,4),plot(x,y,'*'),hold on,plot(scalar_x,y_cubic),title('cubic');
2. 2. 求下列函数的解,并绘制图形。
(1) y=e x-x5,初始点为x=8.
(2) y=xsin(x)
>> y=@(x)exp(x)-x^5;
>> x=fzero(y,8)
x =
12.7132
>> fplot(y,[10,14]);
>> hold on
>> plot(x,y(x),'r*')
>>y=@(x)x*sin(x);
>> x=fzero(y,0)
x =
3.求下列函数的极值。
(1) z=x2-(y-1)2
(2) z=(x-y+1)2
>> z=@(x)x(1)^2-(x(2)-1)^2;
>> [x,fvalue]=fminsearch(z,[-1,1])
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
x =
1.0e+043 *
1.1138 1.2383
fvalue =
-2.9279e+085
>> z = @(x)(x(1)-x(2)+1)^2;
>> [x,fvalue]=fminsearch(z,[-1,1])
x =
>> ezplot(g,[-2,2])
7. 计算下列各式
(1)
(2),求
(3),求,,
(4),
>> limit(sym('(tan(x)-sin(x))/(1-cos(2*x))'))
ans =
>> y=sym('x^3-2*x^2+sin(x)')
y =
sin(x) - 2*x^2 + x^3
>> diff(y)
ans =
cos(x) - 4*x + 3*x^2
>> f=sym('x*y*log(x+y)')
f =
x*y*log(x + y)
>> diff(f,'x')
ans =
y*log(x + y) + (x*y)/(x + y)
>> diff(f,'y')
ans =
x*log(x + y) + (x*y)/(x + y)
>> y=sym('ln(1+t)')
y =
log(t + 1)
>> int(y)
ans =
(log(t + 1) - 1)*(t + 1)
>> int(y,0,27)
ans =
28*log(28) - 27
8.计算下列各式
(1)
(2)