当前位置:网站首页>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

边栏推荐
- 【一起上水硕系列】Day 8
- 成为唯一的key
- matplotlib matplotlib可视化之柱状图plt.bar()
- 机器学习:VC维的概念和用途
- 简单理解B树和B+树
- Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]
- Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column
- constexpr 函数
- 疫情下我离职一年,收入增长了10倍
- 剑指 Offer 15. 二进制中1的个数
猜你喜欢
discrete "digital signal"]"/>Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]

Matplotlib histogram of Matplotlib visualization plt bar()

正则表达式:字符(2)

打造一个 API 快速开发平台,牛逼!

Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column

2022 PMP project management examination agile knowledge points (5)

Open source the Ernie tiny lightweight technology of "Wenxin big model", which is accurate and fast, with full effect

M1笔记本居家办公的痛点及解决方案 | 社区征文

【一起上水硕系列】Day 8

小程序插件接入、开发与注意事项
随机推荐
Leetcode(633)——平方数之和
Principe de réalisation de l'agent dynamique
声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
Yunhe enmo, gaiguoqiang, identify it and grasp it before the domestic database boils
Solr基础操作2
Welcome the "top ten" of the Municipal Association for science and technology • pay tribute to Lu Yi, a scientific and technological worker: an explorer guarding the transmission security of the power
十大券商:“推土机行情”再现
Project 1 - buffer pool [cmu 15-445645] notes
How to solve the problem that the computer time is not automatically updated after proofreading
Profit distribution and taxation of funds
关于二叉树
Node data collection and remote flooding transmission of label information
Shell -- text processing command
Gracefully transform the SMS business module and start the strategic mode!
Halcon实用:焊点检出设计思路
大厂试水 HPE推出Arm CPU通用服务器产品
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
招商证券靠谱吗?开股票账户安全吗?
RRDTOOL draws MRTG log data
Redis client