当前位置:网站首页>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
边栏推荐
猜你喜欢
C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
Paper writing tool: latex online website
Speech signal processing (II): phonation physiology, auditory physiology and auditory psychology
采购数智化爆发在即,支出宝“3+2“体系助力企业打造核心竞争优势
雲和恩墨蓋國强,識別它、抓住它,在國產數據庫沸騰以前
云服务器的安全设置常识
软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数
discrete "digital signal"]"/>
Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]
LC: maximum subarray and
正则表达式:字符(2)
随机推荐
matplotlib matplotlib中plt.hist()参数解释
Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column
剑指 Offer 13. 机器人的运动范围
Leetcode(680)——验证回文字符串 Ⅱ
动态代理的实现原理
M1笔记本居家办公的痛点及解决方案 | 社区征文
手机开户一般哪个证券公司好?另外,手机开户安全么?
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
Matplotlib histogram of Matplotlib visualization plt bar()
LC:有效的数独 + 旋转图像
数据库-玩转数据-Pgsql 使用UUID做主键
label問題排查:打不開標注好的圖像
動態代理的實現原理
Leetcode 1385. 两个数组间的距离值
Solr基础操作5
constexpr 函数
RRDTOOL draws MRTG log data
The concept and significance of mean, variance, standard deviation and covariance
云服务器的安全设置常识
High performance and high availability computing architecture of "Weibo comments"