当前位置:网站首页>Matlab exercises -- program control process exercise
Matlab exercises -- program control process exercise
2022-06-29 23:38:00 【Fanyi】
matlab Series articles : Catalog

One 、 subject
- (1) Building functions , The input variables are sorted by month, year and day 8 An integer ( Such as 20220530), The output variable is the ordinal number of the date in the year
- (2) It is known that 2022 year 1 month 1 Day is Saturday , Building functions , The input variables are sorted by month, year and day 8 An integer ( Such as 20220530), Output the day of the week
- (3) Definition 10 That's ok 8 Column Hilbert matrix ( a i j = 1 i + j − 1 a_{ij = \frac{1}{i+j-1}} aij=i+j−11)
- (4) Generate 100000 The Fibonacci series within , a 1 = 1 , a 2 = 2 , a n = a n − 1 + a n − 2 , n = 3 , 4 , 5 , . . . a_{1}=1,a_{2}=2,a_{n}=a_{n-1}+a_{n-2},n=3,4,5,... a1=1,a2=2,an=an−1+an−2,n=3,4,5,...
- (5) To satisfy the condition n ! > 1 0 15 n! \gt 10^{15} n!>1015 Minimum integer of
- (6) Output all five pointed star numbers ( for example 54748, 5 5 + 4 5 + 7 5 + 4 5 + 8 5 = 54748 5^5+4^5+7^5+4^5+8^5=54748 55+45+75+45+85=54748)
- (7) Interactive input of three real numbers , If this three numbers as the side length can form a triangle , Find the area
- (8) Programming calculation of chicken and rabbit in the same cage ( Thirty five heads , Ninety four feet )
- (9) Drawing piecewise functions f ( x ) = { − x , − 5 < x < 0 x 2 2 , 0 ≤ x ≤ 2 2 s i n ( π x ) , 2 < x < 5 f(x)=\left\{ \begin{aligned} &-x,\qquad&-5\text{\textless}x\text{\textless}0\\\\ &\frac{x^2}{2},\qquad&0 \le{x}\le{2}\\\\ &2sin(\frac{\pi}{x}),\qquad&2\text{\textless}x\text{\textless}5 \end{aligned} \right . f(x)=⎩⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎧−x,2x2,2sin(xπ),−5<x<00≤x≤22<x<5
- (10) Reading data
sd.xlsx, Yes 1,2 Column calculates its sum for each row , And greater than 6 In the 3 Enter letters... In the corresponding row of the column A, Otherwise, enter the letters B, Yes 4,5 Column calculates the difference for each row , Difference greater than 2 In the 6 Enter letters... In the corresponding row of the column AB, Otherwise, enter the letters BA, And fill in the data after the operationsd.xlsx
Two 、 answer
Topic 1
① Building functions , The input variables are sorted by month, year and day 8 An integer ( Such as 20220530), The output variable is the ordinal number of the date in the year
function out = getNum(date)
date_str = num2str(date);
d = [strcat(date_str(1:4),'-',date_str(5:6),'-',date_str(7:8))];
d_new = [strcat(date_str(1:4),'-01-01')];
out = daysact(d_new,d);
end
Topic two
① It is known that 2022 year 1 month 1 Day is Saturday , Building functions , The input variables are sorted by month, year and day 8 An integer ( Such as 20220530), Output the day of the week
function out = getNum(date)
date_str = num2str(date);
d = [strcat(date_str(1:4),'-',date_str(5:6),'-',date_str(7:8))];
out = weekday(d);
end
Question three
① Definition 10 That's ok 8 Column Hilbert matrix ( a i j = 1 i + j − 1 a_{ij = \frac{1}{i+j-1}} aij=i+j−11)
function m = Hilber()
for i=1:10
for j=1:8
a(i,j) = 1/(i+j-1);
end
end
m = a;
end
Question 4
① Generate 100000 The Fibonacci series within , a 1 = 1 , a 2 = 2 , a n = a n − 1 + a n − 2 , n = 3 , 4 , 5 , . . . a_{1}=1,a_{2}=2,a_{n}=a_{n-1}+a_{n-2},n=3,4,5,... a1=1,a2=2,an=an−1+an−2,n=3,4,5,...
function fib_arr = fib(k)
num(1) = 1;
num(2) = 1;
for i=3:k
num(i) = num(i-1) + num(i-2);
if num(i) >= k
break
end
fib_arr = num(1:end-1);
end
Question five
① To satisfy the condition n ! > 1 0 15 n! \gt 10^{15} n!>1015 Minimum integer of
function out = getNum()
num(1) = 1;
for i = 1:1000000
if(num(i) > 10^15)
break
end
num(i+1) = num(i)*i
end
out = num(end-1);
end
Question six
① Output all five pointed star numbers ( for example 54748, 5 5 + 4 5 + 7 5 + 4 5 + 8 5 = 54748 5^5+4^5+7^5+4^5+8^5=54748 55+45+75+45+85=54748)
function out = getNum()
count = 0;
for i=10000:99999
a = fix(i/10000);
b = fix(rem(i,10000)/1000);
c = fix(rem(i,1000)/100);
d = fix(rem(i,100)/10);
e = fix(rem(i,10)/1);
if(a^5+b^5+c^5+d^5+e^5==i)
count = count + 1;
num(count) = i;
end
end
out = num;
end
Question seven
① Interactive input of three real numbers , If this three numbers as the side length can form a triangle , Find the area
function out = getNum(a,b,c)
if(a+b>c && a-b<c)
p = (a+b+c)/2;
s = (p*(p-a)*(p-b)*(p-c))^(1/2);
end
out = s;
end
Question eight
① Programming calculation of chicken and rabbit in the same cage ( Thirty five heads , Ninety four feet )
function out = getNum()
syms x y;
enq1 = x + y == 35;
enq2 = 2*x + 4*y == 94;
A = solve(enq1,enq2,x,y);
out = A;
end
Question nine
① Drawing piecewise functions
x=-5:.1:5;
f=zeros(size(x));
for i=1:length(x)
if (x(i)>-5) & (x(i)<0)
f = -x
end
if (x(i)>=0) & (x(i)<=2)
f = x.^2/2
end
if (x(i)>2) & (x(i)<5)
f = 2*sin(pi./x)
end
end
plot(f,x)

Question 10
① Reading data sd.xlsx, And fill in the data after the operation sd.xlsx
- Program 1
data1=xlsread('F:\sd.xlsx',1,'A1:B191')
for i = 1:length(data1)
if data1(i,1)+data1(i,2)>6
xlswrite('F:\sd.xlsx','A',1,strcat('C',num2str(i)))
else
xlswrite('F:\sd.xlsx','B',1,strcat('C',num2str(i)))
end
end
- Program two
data2=xlsread('F:\sd.xlsx',1,'D1:E191')
for i = 1:length(data2)
if abs(data2(i,1)-data2(i,2))>2
xlswrite('F:\sd.xlsx',{
'AB'},1,strcat('F',num2str(i)))
else
xlswrite('F:\sd.xlsx',{
'BA'},1,strcat('F',num2str(i)))
end
end

边栏推荐
- 绿树公司官方网站
- 均值、方差、标准差、协方差的概念及意义
- Is it safe to open a stock account? Shanghai stock account opening.
- Procurement intelligence is about to break out, and the "3+2" system of Alipay helps enterprises build core competitive advantages
- 招商证券靠谱吗?开股票账户安全吗?
- Some of my favorite websites
- Yunhe enmo Guoqiang, identifiez - le, saisissez - le, avant l'ébullition de la base de données nationale
- label問題排查:打不開標注好的圖像
- 打造一个 API 快速开发平台,牛逼!
- 剑指 Offer 15. 二进制中1的个数
猜你喜欢

Procurement intelligence is about to break out, and the "3+2" system of Alipay helps enterprises build core competitive advantages

海外数字身份验证服务商ADVANCE.AI入选EqualOcean《2022品牌出海服务市场研究报告》

matplotlib matplotlib可视化之柱状图plt.bar()

Leetcode 1385. 两个数组间的距离值

Node data collection and remote flooding transmission of label information

2022 PMP project management examination agile knowledge points (5)

Software testing interface testing postman testing tool interface testing process execution interface testing interface associated environment variables and global variables built-in dynamic parameter

按头安利 好看又实用的点胶机 SolidWorks模型素材看这里

Yunhe enmo, gaiguoqiang, identify it and grasp it before the domestic database boils

InfluxDB时序数据库系统
随机推荐
xutils3传集合
招商证券靠谱吗?开股票账户安全吗?
基金的估值,费用,会计核算
label问题排查:打不开标注好的图像
均值、方差、标准差、协方差的概念及意义
constexpr 函数
Fund information disclosure
Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]
Leetcode(633)——平方数之和
C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
基金的利润分配与税收
机器学习:VC维的概念和用途
Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column
Incluxdb time series database system
Constexpr function
Status acquisition and control system of on-site express cabinet
Profit distribution and taxation of funds
NRM explanation
Redis client
LC: maximum subarray and