MATLAB homework help request

I need help with this question!
The lump sum S to be paid when interest on a loan is compounded
annually is given by S = P(1 + i)n where P is the principal invested,
i is the interest rate, and n is the number of years. Write a function
interest.m that will plot the amount S as it increases through the
years from 1 to n. The main function will call a function to prompt
the user for the number of years (and error-check to make sure that the
user enters a positive integer). The function will then call a function
that will plot S for years 1 through n. It will use .05 for the interest
rate and $10,000 for P.

Antworten (2)

Image Analyst
Image Analyst am 21 Okt. 2012

0 Stimmen

Check out input() or better, inputdlg(). Then check out plot().

11 Kommentare

Ong
Ong am 21 Okt. 2012
Can you explain how do I even start?:/ Sorry, I'm a noob at matlab
Ong
Ong am 21 Okt. 2012
Oh anyway Walter, can I ask..its regarding my other question..how do you create a random number in matlab without any range provided?
TheRandomNumber = rand();
Note that this produces values in the range 2^(-53) to 1-(2^(-53)) -- but at least you didn't have to provide a range.
Ong
Ong am 22 Okt. 2012
How do you know the range values!
Ong
Ong am 22 Okt. 2012
and also for my the other question about converting time into other units, what should the condition for the while loop be?
Image Analyst
Image Analyst am 22 Okt. 2012
What other question about the time units? If you need to compute the current balance monthly or daily, then there is a formula for computing balance monthly or daily given an annual interest rate. I'm sure you can find that.
What while loop? I'd use a for loop "for y = 1 : n".
Ong
Ong am 22 Okt. 2012
This is my other question:
Write a menu-driven program convertTime.m to convert a time in seconds to other units (minutes, hours, days). The main function will loop to continue until the user chooses to exit. Each time in the loop, the function will generate a random time in seconds, call a function to present a menu of options, and print the converted time. The conver- sions must be made by individual functions (e.g. one to convert from seconds to minutes, one to convert from seconds to hours, and one to convert from seconds to days). All user-entries must be error-checked.
Which command to use for the looping part?
Walter Roberson
Walter Roberson am 22 Okt. 2012
What range values are you referring to? I don't understand why you are asking about random numbers at all, as the assignment you posted has no randomness to it.
If you are asking how I know that rand() produces values in the range 2^(-53) to 1-(2^(-53)), then the answer is that I have memorized those limits from documentation for previous MATLAB versions when the ranges were clearly presented instead of being a struggle to find (as they are in the current documentation.)
Ong
Ong am 22 Okt. 2012
I was thinking of while loop..but again, if I do use that I cant figure out the condition.
Walter Roberson
Walter Roberson am 22 Okt. 2012
The discussion of your other question should happen in your other question.

Melden Sie sich an, um zu kommentieren.

Matt J
Matt J am 21 Okt. 2012
Bearbeitet: Matt J am 21 Okt. 2012

0 Stimmen

Should be easy. Use the INPUT command to get the user input. Then
if isnumeric(n) && isreal(n) && n>=0
etc...
end
Then apply the compounding formula. Then the PLOT command.

4 Kommentare

Ong
Ong am 21 Okt. 2012
Can you explain how do I even start?:/
Matt J
Matt J am 21 Okt. 2012
Bearbeitet: Matt J am 21 Okt. 2012
I did. Use the INPUT command to get the user input. Then
if isnumeric(n) && isreal(n) && n>=0
etc...
end
Then apply the compounding formula. Then the PLOT command.
Ong
Ong am 21 Okt. 2012
Its not working! Do you have the solution to provide me with so that I can check where went wrong?
Matt J
Matt J am 21 Okt. 2012
I do not. However, you can step through the code 1 line at a time and examine the results by setting breakpoints

Melden Sie sich an, um zu kommentieren.

Gefragt:

Ong
am 21 Okt. 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by