2-Consider the following iterative process. Start with a positive integer n. Replace it
with n/2 if n is even and with 3n + 1 if n is odd and repeat this process with the new number that
was obtained.
For example, if n = 10 we obtain the sequence 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, . . . . If n = 7 we obtain the
sequence 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, . . . .
Write a script M-file q1 10b that assumes a variable n is defined and assigned an integer value. The
script will produce a vector x with the results of the first 50 iterations obtained in the process described
above. Then the script should plot a graph of the iteration number against the integer obtained in
that iteration.
Test your script and plot the graphs when n = 19 and n = 21.
3-The purpose of this exercise is to find a numerical solution for the ODE
?x + 3x2 x˙ t = 5 cos(t)
in the interval [0, ] and with initial values x(0) = 1, x˙ (0) = −1.
(a) Write (in your log-book) an equivalent system of two linear ODE’s.
(b) Write a function q2 5f whose input is a number t and a column vector u of length 2 and whose
output is a column vector v of length 2.
Write a script file q2 5s that invokes ode45 and uses the function q2 5f in oder to obtain a numerical
solution to the system of ODE’s in (a). The script must also plot the graphs of x(t) and x˙ (t).
4-Write a script M-file e3q1.m containing appropriate MATLAB commands for
the questions below.
(i). Use dsolve to find the exact (analytic) solution of the second order initial value problem
15x? − 2x˙ = −x + sin(3t) with x = 0, x˙ = 0.4 when t = 0.
(ii). Use diff to find an expression for y = dx/dt in terms of t where x(t) is the solution of the
differential equation above. You may want to use the command pretty( ) to print the result.
So... what do you need help with?
All you did was post your (school) assignment.
Show your work (what you've tried so far), show what you're stuck on,
and ask for specific help.
Don't expect people to do things for you.
-Nathan
> i would like you to solve this questions not just for me but the hall class
Might there also be some starving children who can benefit from our solving these questions for you?
>
> Might there also be some starving children who can benefit from our solving these questions for you?
But hey Matt you are right on track here, as John often predict the future, there is a good chance that will happen if the OP end up in working at Burger King.
Bruno
It's hard to believe that the "hall class" are a bunch of cheats like
the OP.
Surely, there's one honest student in the class who is prepared to do
their own homework?
Otherwise, I'm afraid the world is doomed............
%%%%%%%%%%%%%%%%%%%
function res=you_lazy(n)
if floor(n/2)-ceil(n/2)==0
res = n/2;
else
res = 3*n+1;
end
end
%%%%%%%%%%%%%%%%%%%%
floor : Round toward negative infinity
ceil : Round toward positive infinity
Sauve la function ci-dessus dans un m-file intitul? you_lazy.m
Dans le "Command Window", tape you_lazy(5) par exemple.
I am sure most of the people posting in this thread know the answers
for your simple questions but that is your homework, not theirs...
>and by the way iam studient iam learning
no you are cheating (or trying to do so)...
The solutions to all of your problems are to be found here:
Envision a bright and fulfilling career. Practice these words:
"Do ya want fires with that?"
> Write a function q1 10a that receives an integer n and returns n/2 if n was even and
> 3n + 1 if n was odd. To test if a number is an integer it is convenient to use the MATLAB function
> floor( ) which returns the largest integer smaller than the input number. For example floor(4.9)
> = 4 and floor(-1.1)=-2 and floor(15)=15. (Try this out!)
Herve wrote:
> function res=you_lazy(n)
> if floor(n/2)-ceil(n/2)==0
> res = n/2;
>else
> res = 3*n+1;
>end
>end
This is not complete. The question involved the request for trying the FLOOR command. So:
floor(4.9) ==> indeed 4 is replied.
floor(-1.1) ==> indeed -2 is replied.
floor(15) ==> indeed 15 is replied.
In addition the OP asked for multiple solutions. A 2nd one:
function res = q1_10a(n)
if floor(n/2) * 2 == n
res = n/2;
else
res = 3*n+1;
end
return;
3rd one:
function res = q1_10a(n)
res = n/2;
if floor(res) ~= res
res = 3*n+1;
end
return;
4th one:
function res = q1_10a(n)
res = round(n / 2 - (floor(n / 2) - n / 2) * (5 * n + 2));
return;
I hope, this is enough.
Question 2 is solved most efiiciently with a lookup table:
function q1_10b(n)
switch n
case 19
plot([58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1]);
case 21
plot([64, 32, 16, 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4]);
end
return;
Other solution might be more flexible. But this is not demanded in the question! Keep it simple! Less commands mean less danger for bugs.
> Question 3: ... the ODE ?x + 3x2 x˙ t = 5 cos(t)
> in the interval [0, ] and with initial values x(0) = 1, x˙ (0) = −1.
> (a) Write (in your log-book) an equivalent system of two linear ODE’s.
What might "?x + 3x2 x˙ t = 5 cos(t)" mean?! Is the interval transcendental? What is a log-book?
Finally: Have you learned anything by reading this answer?
1. Bruno, TideMan and Matt have done their homework.
2. It's not their task to solve yours.
3. They know, that copy&paste is not part of solving homework.
4. Bruno thinks, that Burger King is a solution for starving children - Bruno! Bad!! (Perhaps this is a violation of human rights?)
5. Do not loose your humor. This is only science, not the real life.
It would be easier to read your messages, if you'd insert some dots. A lot of the readers are no native English speakers. Thanks.
Jan
John:
> "Do ya want fires with that?"
Dyslexics of the World: Untie!!
but - jd/tm - there's some bad news for the OP if he/she follows the link:
- there's this purple button right behind the nave of the tumbling wheel, which clearly states
...
due to increasing demand of our wlan using toddlers and their mothers, applicants are now required to produce proof of utmost fluency in the high-level computer language MATLAB in order to be ready to solve the homework assignments of our youngest clientele
...
us
> thank you very much for your help i much aperciat this exampl probabaly very easy but a lot harder for me i aperciat u havent understand the writing one of the studient have posted this example on webside have look he is very clear
Stop posting your homework assignments and spend
the time doing them instead. Learn to be a useful
member of society instead of a leech.
plonk
It very much is homework, even if you claim to
have "assigned" it to yourself.
You have not tried a single thing that you have shown.
So even in the unlikely event that you really do want to
learn matlab on your own, the best way is for you to
start trying to use the tool. Our doing this for you does
you NO good at all.
Try to write something. Make some mistakes. Otherwise
you will never learn a thing. And if you do try it and
something does not work, then and only then will
someone help you with the problem. And you will
ONLY get help if you show what you tried.
Pleading for someone to do your homework will
get you nothing except waste your own time and
network bandwidth.
Well, this is Usenet and we will do and say as we please, and there's
nothing you can do about it.
Are you thick, or is it a language thing?
Have you not got the message that we don't help homework cheats?
> Well, this is Usenet and we will do and say as we please, and there's
> nothing you can do about it.
> Have you not got the message that we don't help homework cheats?
Helping homework cheaters is not helping them
Not helping them is helping them.
This is the educational duality.
Anyhow, this is Usenet and we cannot avoid, that students post their homeworks. ;-)
Kind regards, Jan
> thank you very much for your help i much aperciat this exampl probabaly very easy but a lot harder for me i aperciat u havent understand the writing one of the studient have posted this example on webside have look he is very clear
> 1-http://www.postimage.org/image.php?v=aV1aPjTJ
> 2-http://www.postimage.org/image.php?v=aV1aPGl0
> 3-http://www.postimage.org/image.php?v=aV1aPViS
> this the three links so you can read them properly thank vey much for help in advance much aperciat it and well done for the first example
I pleased you to insert dots in your posts to separate the sentences.
As far as I understand, you do not like my solution for the 2nd question?!
What a pitty. It's optimal. I'm sure your teacher will like it. But he will not like it to read, that he is not a good teacher. And he will remember, who has written the "solutions". Do your think he has no internet access?
You are really funny, when you assert, that John does not know the solutions. A strange kind of humor, but humor. But do not forget to read what he was writing! He offered the true treasure here.
Have fun with learning Matlab. I'd suggest to start with something easier than question 3.
Kind regards, Jan
> >
> > > plonk
> >
> > this is not home work this examples we want to learn from them ok and there is no need for insulting people i think most of the bad comment comming for the people they dont know the solution because if you know the solution i think this very easy because this is a basic of matlab equation so please any one doesnt know the solution dopnt bother to write a comment all what i ?was needing is help if you cant solve it dont write any comment please
>
> Well, this is Usenet and we will do and say as we please, and there's
> nothing you can do about it.
> Are you thick, or is it a language thing?
> Have you not got the message that we don't help homework cheats?
first iam not cheating second this is my first time doing this matlab in my life third is not home work fourth iam not thick you consider me as thik because you know the solution once again did you forget we need to learn in life what goes round comes round you never know in life you may need help in your future andsome one turned to you and inslut you .than you will realise how i feel about your comment wel please for everybody in this forum a bit of respect
what have YOU done so far to solve YOUR interesting problem?
us
> first iam not cheating second this is my first time doing this matlab in my life third is not home work fourth iam not thick you consider me as thik because you know the solution once again did you forget we need to learn in life what goes round comes round you never know in life you may need help in your future andsome one turned to you and inslut you .than you will realise how i feel about your comment wel please for everybody in this forum a bit of respect
I respect someone who tries to do their own work. This
is the best way to learn to program. It is also how you
learn to do many other things.
Sit down, relax. Get your hands dirty. Make many
mistakes. We have all made those same mistakes. But
unless you make them, you will not understand why
they are mistakes.
If we give you the solutions with no effort from you,
then you learn nothing, and we just waste our time
too. So start writing. I know, it hurts to think. But
your brain is a muscle, and unless you use it, the
muscle atrophies.
One thing that I have suggested before, is to work
with other students in your group. If you truly have
some others with you who don't know anything
about matlab, then form a group. Teach each other
to use the language. This works because as you
explain something to another, you will find that you
come to understand it better yourself.
So I am sorry, but until you show that you have
made some effort to learn this tool, then I have no
respect for you.
John
thank you very much honestly i liked your advice and the way you guide me well done. the problem is i have tried the first question a put it in m-file and tried to run it from the m-file i always get errors and second to work with student or as group that was a good idea unfortuntly non of us understand matlab because we had three or four lecture about matlab and the lecturer didnt explain it well when we asked question he refuse to answer us all what he say "trust me i know how to do it but i dont have time to do it" the problem we want the solution is work out on solution and find out the meaning of the command if we dont have the right solution non of us know weither is the right result or not.what we do for other modul for exmple we get result and check in books how did they get the result and why if you know what mean anyway thank you very much you were very kind much aperciat your
advice
> thank you very much honestly i liked your advice and the way you guide me well done. the problem is i have tried the first question a put it in m-file and tried to run it from the m-file i always get errors
Stop there. If you have tried something, then show
us what you tried!!!!
We can help you fix it. As I said, I will never complain
if you make an effort. But simply asking us to do
something for you shows no effort on your part.
Show some interest and you will find those who will
meet you half way. This is the very best way to get a
response. Show no interest beyond pleading for help,
and you will gain nothing but derision.
> and second to work with student or as group that was a good idea unfortuntly non of us understand matlab because we had three or four lecture about matlab and the lecturer didnt explain it well when we asked question he refuse to answer us all what he say "trust me i know how to do it but i dont have time to do it" the problem we want
Sit down together with your friends. Talk about
it. You will be surprised that together, you know
more than you think. You can work it out, but
you will NEVER learn if you never try. Student
work groups do work. (I can assert this, because
I too was once a student in the deep, dark, past.)
John
The problem is you're not showing any of your work but just writing prose.
Post (hopefully succinct) sections of your m-file code w/ the specific
problems you're having and what you expect as result. As John says,
then you'll get responses from (possibly several) who will be happy to
help when it is, as John says, clear you're in this with us and making
the effort and as importantly providing something concrete to actually
respond to...
--
Assuming you are using a PC.
In the Matlab editor, hit Ctrl-a, then Ctrl-c, then in the message hit
Ctrl-v.
Ctrl is the key at the bottom left of your keyboard.
You must hold this key down as you strike the letters.
It's called "copy and paste".
Ctrl-a selects the whole file
Ctrl-c copies it to the clipboard
Ctrl-v pastes it into the message.
If you need help with this, ask any 10-year old kid.
> > --oh thank you guys for your help the problem i dont know how to upload the m-file to this forum because iam new on this site.can anyone show me or guide me how to upload the m-file in site cheers
You don't upload it. You simply paste it in. You
were able to paste in the original file that started
this thread.
copy
paste
In addition to the other responses -- this isn't a "forum", c.s-s.m is a
usenet newsgroup (see wikipedia if don't know what that means). The TMW
portal is simply a gui TMW provides to the text-based usenet group.
Secondly, make your postings _CONCISE_ and specific -- posting long
sections of code w/ "it doesn't work" will get nothing but ignored.
Need short-enough sections of code folks can see/read it quickly and
respond the same. It needs a concise and complete description of the
objective, necessary data if any to demonstrate the problem and an
explanation of what the desired result would be...
--
*snip*
> Sit down together with your friends. Talk about
> it. You will be surprised that together, you know
> more than you think. You can work it out, but
> you will NEVER learn if you never try. Student
> work groups do work. (I can assert this, because
> I too was once a student in the deep, dark, past.)
In addition to what John suggested, I recommend you work through the
documentation (at least the Getting Started guide) that you can access by
typing "doc" (without the quotes) at the MATLAB prompt. Make sure that as
you read each page of the documentation that you understand what it says.
Execute the code examples on those documentation pages and make sure you
understand why you receive the results you do. You can also read through
some the demos that ship with the product and learn from them.
Everyone (well, except for Cleve Moler, but he's a bit of a special case)
was new to MATLAB once -- even the gurus on this newsgroup, like John, were
newbies at one point. We all survived it :)
http://www.mathworks.com/company/aboutus/founders/clevemoler.html
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ