MATLAB Programming With Applications For Engineers 1st Edition Chapman Solutions Manual 1
MATLAB Programming With Applications For Engineers 1st Edition Chapman Solutions Manual 1
MATLAB Programming With Applications For Engineers 1st Edition Chapman Solutions Manual 1
% Convert to radians
theta_rad = theta * pi / 180;
% Calculate tangent
if abs(cos(theta_rad)) > 1E-20
tan = sin(theta_rad) / cos(theta_rad)
else
disp('Error: cos(theta) too small');
end
4.3 These statements will execute, but they will not produce the result that the programmer wanted. An
if/elseif/else structure will take the first valid branch, and ignore all others. Thus, if the
temperature is 105, the statement will display the message 'Temperature normal' instead of
the desired message. This problem can be fixed by restructuring the order of the statements. In
addition, the structure would not print out a message if the temperature were exactly 97.5. A
corrected version of the statements is shown below.
66
© 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% cost -- cost in dollars
% weight -- Weight of package (lbs)
% Calculate cost
if weight > 100
% Not mailable
disp('Packages heavier than 100 pounds cannot be mailed!');
else
if weight <= 2
cost = 15;
else
cost = 15 + (weight-2) * 5.00;
end
% Apply penalty
if weight > 70
cost = cost + 15;
end
% Display weight
fprintf('Cost = $%.2f\n',cost);
end
» mail
Enter weight of parcel, in lbs: 1
Cost = $15.00
» mail
Enter weight of parcel, in lbs: 10
Cost = $55.00
» mail
Enter weight of parcel, in lbs: 80
Cost = $420.00
» mail
Enter weight of parcel, in lbs: 120
Packages heavier than 100 pounds cannot be mailed!
67
© 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% |
% | x + y x >= 0 and y >= 0
% | x + y**2 x >= 0 and y < 0
% f(x,y) = | x**2 + y x < 0 and y >= 0
% | x**2 + y**2 x < 0 and y < 0
% |_
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 01/03/10 S. J. Chapman Original code
% 1. 06/20/11 S. J. Chapman Modified for nested ifs
%
% Define variables:
% x -- First independent variable
% y -- Second independent variable
% fun -- Resulting function
68
© 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
%
% Define variables:
% x -- First independent variable
% fun -- Resulting function
» eval_fn
Enter x: 2
x must be < 1!
» eval_fn
Enter x: 0
log( 1 / (1-x) ) = 0
» eval_fn
Enter x: -1
log( 1 / (1-x) ) = -0.69315
4.7 A program to convert a day name to a day number using a switch construct is shown below:
% Convert to number
switch (day)
case {'Sunday'},
day_no = 1;
case {'Monday'},
69
© 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Another document from Scribd.com that is
random and unrelated content:
Transcriber’s Notes:
The illustrations have been moved so that they do not break up paragraphs and
so that they are next to the text they illustrate.
Typographical and punctuation errors have been silently corrected.
Many of the illustrations are not in numerical order. This is not a mistake, it is part
of the original book.
*** END OF THE PROJECT GUTENBERG EBOOK MODEL
AEROPLANES ***
Updated editions will replace the previous one—the old editions will be
renamed.
Creating the works from print editions not protected by U.S. copyright
law means that no one owns a United States copyright in these works, so
the Foundation (and you!) can copy and distribute it in the United States
without permission and without paying copyright royalties. Special rules,
set forth in the General Terms of Use part of this license, apply to
copying and distributing Project Gutenberg™ electronic works to protect
the PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if you charge
for an eBook, except by following the terms of the trademark license,
including paying royalties for use of the Project Gutenberg trademark. If
you do not charge anything for copies of this eBook, complying with the
trademark license is very easy. You may use this eBook for nearly any
purpose such as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and printed and
given away—you may do practically ANYTHING in the United States
with eBooks not protected by U.S. copyright law. Redistribution is
subject to the trademark license, especially commercial redistribution.
1.D. The copyright laws of the place where you are located also govern
what you can do with this work. Copyright laws in most countries are in
a constant state of change. If you are outside the United States, check the
laws of your country in addition to the terms of this agreement before
downloading, copying, displaying, performing, distributing or creating
derivative works based on this work or any other Project Gutenberg™
work. The Foundation makes no representations concerning the
copyright status of any work in any country other than the United States.
1.E.1. The following sentence, with active links to, or other immediate
access to, the full Project Gutenberg™ License must appear prominently
whenever any copy of a Project Gutenberg™ work (any work on which
the phrase “Project Gutenberg” appears, or with which the phrase
“Project Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
eBook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form, including
any word processing or hypertext form. However, if you provide access
to or distribute copies of a Project Gutenberg™ work in a format other
than “Plain Vanilla ASCII” or other format used in the official version
posted on the official Project Gutenberg™ website (www.gutenberg.org),
you must, at no additional cost, fee or expense to the user, provide a
copy, a means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other form.
Any alternate format must include the full Project Gutenberg™ License
as specified in paragraph 1.E.1.
1.E.7. Do not charge a fee for access to, viewing, displaying, performing,
copying or distributing any Project Gutenberg™ works unless you
comply with paragraph 1.E.8 or 1.E.9.
1.E.8. You may charge a reasonable fee for copies of or providing access
to or distributing Project Gutenberg™ electronic works provided that:
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the method
you already use to calculate your applicable taxes. The fee is owed
to the owner of the Project Gutenberg™ trademark, but he has
agreed to donate royalties under this paragraph to the Project
Gutenberg Literary Archive Foundation. Royalty payments must be
paid within 60 days following each date on which you prepare (or
are legally required to prepare) your periodic tax returns. Royalty
payments should be clearly marked as such and sent to the Project
Gutenberg Literary Archive Foundation at the address specified in
Section 4, “Information about donations to the Project Gutenberg
Literary Archive Foundation.”
• You provide a full refund of any money paid by a user who notifies
you in writing (or by e-mail) within 30 days of receipt that s/he does
not agree to the terms of the full Project Gutenberg™ License. You
must require such a user to return or destroy all copies of the works
possessed in a physical medium and discontinue all use of and all
access to other copies of Project Gutenberg™ works.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
The Foundation’s business office is located at 809 North 1500 West, Salt
Lake City, UT 84116, (801) 596-1887. Email contact links and up to date
contact information can be found at the Foundation’s website and official
page at www.gutenberg.org/contact
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of other
ways including checks, online payments and credit card donations. To
donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search facility:
www.gutenberg.org.