温州大学物理与电子信息工程学院
Matlab仿真及其应用 实验报告
实验名称:实验三 Matlab基本编程操作
实验目的:
1、 熟悉Matlab的脚本编写
2、 熟悉Matlab的函数编写
3、 书写Matlab的变量使用
4、 熟悉Matlab的程序控制结构
实验内容:
1. 分别选用if或switch结构实现函数表示
2. 根据近似计算指数,当与指数函数的误差小于0.01时停止,分别用for和while 结构实现。
3. 迭代计算,给出可能的收敛值,并给出不同收敛对应的处置范围。
4. 在第3题的代码中增加try和catch控制块,以避免出现的情况
5. 从键盘输入数值,迭代计算
实验结果及分析:
1、分别选用if或switch结构实现函数表示
新建M-file
编写程序
function y=function1(x,a)
if x<=-a
y=-1;
elseif -a<x&&x<a
y=x/a;
else
y=1;
end
保存后在命令窗口键入y=function1(1,5)
运行结果:
Switch实现:
function y=function1(x,a)
switch x
case x<=-a
y=-1;
case -a<x&&x<a
y=x/a;
otherwise
y=1;
end
保存后在命令窗口键入y=function1(1,5)
运行结果:
>> y=function1(1,5)
y =
0.2000
2、根据近似计算指数,当与指数函数的误差小于0.01时停止,分别用for和while 结构实现。
用for 结构实现:
用for结构:
function y=function3(x)
y=1;t=1;a=x;m=y+x;
for i=1:inf
if (m-y)>=0.00001
y=y+a/function1(t);
a=a*x;
t=t+1;
m=y+a/function1(t);
else
break;
end
end
end
function y=function1(n)
y=1;
for i=1:1:n
y=y*i;
end
end
运行结果:
用while 结构实现:
function y=function1(x)
y=1;i=1;a=1;
while abs(a*(x/(i+1)-1))>0.00001|i<10
a=1;
for i=1:1:i
a=a*x;
a=a/i;
end
y=y+a;
i=i+1;
end
运行结果:
3、迭代计算,给出可能的收敛值,并给出不同收敛对应的处置范围。
function y=function3(x)
x0=x/2;
x1=3/(x0+2);
while abs(x0-x1)>=0.00001
x0=x1;
x1=3/(x0+2);
x1
end
4、在第3题的代码中增加try和catch控制块,以避免出现的情况
function y=function4(x)
x0=x/2;
x1=3/(x0+2);
while abs(x0-x1)>=0.00001
x0=x1;
x1=3/(x0+2);
try
x0=-2;
catch
disp('error');
end
end
5、 从键盘输入数值,迭代计算
function function5()
x=input('input a number:');
x0=x/2;
x1=3/(x0+2);
while abs(x0-x1)>=0.00001
x0=x1;
x1=3/(x0+2);
x1
end
运行结果
>> function5()
input a number:5
x1 =
1.1250
x1 =
0.9600
x1 =
1.0135
x1 =
0.9955
x1 =
1.0015
x1 =
0.9995
x1 =
1.0002
x1 =
0.9999
x1 =
1.0000
x1 =
1.0000
x1 =
1.0000
评定成绩:
第二篇:My thoughts about the Lady of the Camellias茶花女英文读后感
The Lady of the Camellias by Alexandre Dumas fils
Class_3
No.
Name
My thoughts about the Lady of the Camellias
The Lady of the Camellias also called La dame aux camélias in French is a novel written by Alexandre Dumas fils. This novel tells about a love story between a prostitute, Marguerite Gautier and a young provincial bourgeois, Armand Duval. Though Marguerite Gautier was a prostitute, she had a pure heart. She fell in love with Armand Duval, and then tried to escape from her questionable past. They loved each other very much, and they even imagined a picture of their bright future and happy life. However, things always do not go as expected. Unfortunately, the former life came back to haunt her and she returned to that life again and died painfully and alone. And because of many other factors , their love ended up with a tragedy.
The female protagonist in this novel was a poor village girl. She was very beautiful and kind-hearted. In order to earn her living, she became a prostitute, but she still was a noble woman at heart. She longed for true love, and then she lost her heart to Armand Duval. She was not like other prostitutes, and she had her own thoughts. Outwardly, she lived a voluptuous life, bur she was depressed in her heart. She was eager to go back to a ordinary life. Just because that, when Armand Duval ran after her , she fell for him quickly.
Maybe because she lived in such a insincere society for a long time that she took her love more important than any other things. She would gave her whole world for her love. She did not want the money to be involved in their love. She didn't want to spend Armand Duval's money, because she thought the money would contaminate their pure love and she did not want Armand Duval to make a mistake that she was a material woman. She just wanted a pure love without any other things. Therefore, she tried her best to support their love. After their source of income from the old duke was cut, Marguerite Gautier started to sell all her things to pay her debts and support their life without telling Armand Duval. This action expressed how important Marguerite Gautier took their love and how much she loved the man.
But on the other hand, Marguerite Gautier was a little stupid. She believed that as a prostitute, it was a big favor to accept a pure love from the fate. So she should do more to repay it. How silly she was! She was wrong. She did not know the true love was not only to share happiness but also to share sorrows. She should tell her thoughts to Armand Duval and solve the problem with him instead of by herself. And if so, there was no gap and suspicion between them.
Another characteristic of Marguerite Gautier was she was too kind-hearted that she lacked rebellious spirit. She always had consideration for others, but forgot herself. When Armand Duval's father persuaded her to give up their love and told her that if they lived together , it will ruined the future of Armand Duval and the marriage of the Armand Duval's sister, she really did so regardless of her own feelings. Because she knew she was just a prostitute, she had no right to destroy others' futures and she did not want to do that. She loved Armand Duval very much and she wished him a better life even if she could not live with him. Therefore, she decided to give up their love and bore all the consequences and pains by herself. She was such a selfless lady!
To some degree, the tragedy of Marguerite Gautier was made by herself. She was so kind-hearted, selfless, and considerate. She did not to resist. But there were some other reasons. Armand Duval was skeptical and recreant. He always suspected Marguerite Gautier's love for him and even hurt her when he misunderstood her. And if Armand Duval could be determined, when facing his father, they might not separate at last. All these things were responsible for their love tragedy.
Personally, I think the biggest obstacle was society. Because it was Capitalist system in that time. Everybody was money-mad and they just valued the money and the social position. The did not allow a prostitute to marry a person who had a good social position. Or they will look down on the person and despised him. Let us imagine that if Armand Duval's father was in favor of them and made them get married, they still would not be accept by society and the public. How could they live? Would they have a happy life? Of course not! So the society should took the most responsibility for their tragedy. And their tragedy was not theirs but also reflected the tragedy of society.