@@Ivanwu-0324 on windows, I pressed ctrl+r to comment everything that is highlighted. There is also a key at the top of the screen that will do the same. It is labeled Comment.
Two questions: 1. At 1:17 you make the 3 lines "%" how do you do that? 2. how do you get that big letters? Btw thanks for the video. really helped - this is actually easypeasy
I'm glad the video was helpful! To answer your questions: 1) In the editor, there is a button (under the "Edit" menu) called "Comment". You can highlight text and press the button, and it will comment the highlighted text out, or you can use a shortcut (Ctrl+r on Windows), which is what I did. To uncomment, there is also a button for that, or a shortcut (Ctrl+t on Windows), which is what I use. 2) To get big letters, or to change the font in general, in the command window, under the "Environment" menu, click on "Preferences". A new window will open, and in the left menu, select "Fonts". You should then see options for font type, text style, and text size. I used size 24 in the videos.
The easiest (though not the most proper) way to do this would be to declare an empty matrix before the loop, and to concatenate the next result to this matrix after every loop iteration. For example, something like this: bal = 5000; year = 0; bal_vec = []; while bal
Write the JavaScript to read a positive number from the user and then print to the console the numbers from 1 to the user entered number. Ex. If the user enters 50, you should print the numbers 1 to 50 in the console.
This video is about MATLAB, not JavaScript. I could help you solve the problem in MATLAB, although I would use a for loop, not a while loop. For example, you could use: x = input('Please enter a number: '); for ii = 1:x disp(ii); end
hi ive got a question, what is a(counter) and does sum_a equal 0 in every new loop and a(counter) just becomes 1,3,6,10... respectively to make the sum equal to 1,3,6,10...etc.?
The variable "a" is a vector, and "counter" is a scalar. Therefore, "a(counter)" is a given value of "a". For example, if "counter" = 5, then "a(counter)" = 5, since the 5th value of "a" is 5. The variable "sum_a" is keeping track of the current sum of the elements of "a". In every loop iteration, the next value of the vector "a" gets added to the running total in "sum_a". In general, no variable will become 0 at the start of a loop iteration unless it is explicitly declared to do so. Here, "sum_a" is only declared to be 0 once outside of the loop, and therefore its value will not be reset.
Thanks a lot! I actually find this tutorial really helpful. Before I saw this tutorial I was very confused about the structure of the while loop. Now I finally understand what is going on here...appreciate your help doc!
Thanks for the video, it helped me lot. I am curious to know, how you put a percentage sign to more than one line in a single click, can you tell me command you used??
I'm glad I could help! To comment multiple lines, you first highlight them. Then, there is a button at the top of the editor called "comment". Or if you are using Windows, you can click CTRL+r (and CTRL+t to uncomment). I hope this helps!
The explanation was very clear, thank you! However, I have a question about the example with money investment. Is there a possibility to get exactly the value < 1 mln dollars? I mean - how to make a while loop that wouldn't count the last, "excess" value. In this example, one can see that the final amount of money is above 1 mln dollars despite the condition for the loop. Is it only possible to, e .g. display the n-1 value to do it easily?
There are many ways to accomplish this, but I think that the following is more-or-less straightforward. bal_old = 0; bal_new = 5000; year = 0; while bal_new < 1000000 bal_old = bal_new; bal_new = 1.08*bal_old + 5000; year = year + 1; end disp(year-1) disp(bal_old) The idea is that we now have two "balance" variables, one to keep track of the new balance, and one to keep track of the previous balance. This way, when the new balance passes the threshold, we can always reference the previous balance. I hope this makes sense!
Hey I have a question: how can you make a while loop that repeats until a certain variable, vector L, does not change? I though about starting with "while K ~= L" and then put "K = L;" before the for-loop that changes L, but then the while-loop, of course, stops immediately. (To be more specific, I have an assignment for which I need to write a function that implements the k-means algorithm.)
When you use a vector for the condition of a while loop, ALL elements must be true in order for it to execute. For example, "while [1 1 1]" will execute, whereas "while [1 0 1]" will not. Therefore, in your condition, ALL elements of K and L must have been different for the loop to keep running. Instead, you could use the "norm" function. You can then analyze the norm of the difference of the two vectors. For example, you could use "while norm(K-L) > 0", since you know that if the norm is not zero, then the vectors are not the same.
I am assuming you are referring to the example at 6:05. Here, the variable "a" is a vector of values. The variable "counter" is our index. We go through each value in "a", one by one (by incrementing "counter" by 1 every iteration), and add that value to the running total ("sum_a"). I hope that makes sense.
how do you put an or function in the while loop? specifically im trying to have the loop continue until the inputted value for a variable (a) is equal to one of three values. so for example until a is equal to 1 2 or 3 it will continue to prompt the user to input a valid value for a
The easiest way to do this is to use the OR operator (||). So you would have something like "while ~(a==1 || a==2 || a==3)". For more details on logical operators, check out my Logical Expression video. I hope this helps!
man I really love u . u make the life easier with Matlab , but if u don't mind, what's the difference between for loop and while I know if statments only used for bigger, smaller or qual to
Thank You. Just wanted to ask how do you store results in a vector for while loop? Because you wouldn't know what size zero vector to create before the while loop.
Harjinder Singh I apologize this response is so late. For a while loop, you could create a vector of zeros that would be large enough to accommodate any output your while loop could create (e.g. zeros(10000000,1)). Then, you can keep track of your iterations with a counter and trim off the end beyond the value of the counter. Alternatively, you could use dynamic allocation. For example, you could start with an empty vector (e.g. x=[]). Then, every time you want to store a new value y, use x = [x;y]. This concatenates the running x vector with the new value, and thus actively grows it as the program runs. I hope that helps!
+Yvonne Chang You can absolutely do that. The exact structure would depend on the application. The easiest way would be to have something like "while 1", but then the only way to get out of the loop would be a forced exit. Alternatively, you can keep looping until the input is a particular value, for example the letter "q". I hope this helps!
Multiplying by 1.08 only accounts for the interest rate, since it adds 8% of the current balance. Then, since we also want to include an independent deposit, we must add a separate value. I hope this clears things up!
HotDaffodil In the editor, there is a button that says "Comment". You can highlight text and click it. In the video, I used the shortcut for it, which is "Ctrl + r" on a Windows computer.
You could use a for loop and go through the possible values of a and c, keeping the results when both criteria are satisfied. For example: a_vals = []; for a = -10:40 for c = -10:40 if a+c==30 && c-a>=2 && c-a
There is a formula for compound interest C=P(1+r)^n; where P= Principal/ Initial Amount; r= Rate of Interest; n= # of year. In this case we have to find when our balance will reach 1,000,000? While it is given that initial amount is 5,000 and rate of interest is 8%. Ans. In this case 5,000*(1+.08)^n >=1,000,000 => (1.08)^n >=200. So n >=68.84. So you need 69 years to surpass 1,000,000. After 69 years your balance will become $1012066.69. But your program calculated it 36 years and 1,015,400. Make me correct if I am wrong.
i still don't understand this line of code - sum_a = sum_a + a(counter). specifically the a(counter) part. Sorry, if its a stupid question. But i have seen you do this in your for loops video. why can't i just use ''sum_a=sum_a + counter''. I get the same answer with you if i do this. And this makes more sense to me or maybe I still don't understand the a(counter) part.
+sola ade That's an excellent question. The reason I use a(counter) is to keep things as general as possible. The vector "a" can contain any values (not necessarily just 1, 2, 3, etc.), and the variable "counter" is a counter, which increments by 1 every loop iteration. The point, in general, is to use "counter" as an index into the vector "a" and use the next value in "a" for whatever operation you want to perform. In the example at 5:34, the vector "a" is just composed of incrementing values, so in effect, "a(counter)" is equal to "counter" itself. However, imagine if you want to add the values in the vector "a = [2 5 -4 3]". Then, "sum_a = sum_a + a(counter)" would give you very different results than "sum_a = sum_a + counter". This is because "sum_a = sum_a + counter" will always add "counter" to the running total, whereas "sum_a = sum_a + a(counter) will add the "counter"th value of the vector "a". I hope this makes sense!
i have a code for harmonic flow and power flow but i dont understand it.i want to know if you can be of help to run it the matlab because anytime i run it brings NaN
+Taiwo Babatunde I can help with general MATLAB concepts, but not with individual problems. If you have a general "while loop" question, I'd be happy to help.
The easiest method would be to declare an empty matrix, and to increase its size at each iteration by appending the current balance. An example is shown below: bal = 5000; year = 0; bal_vec = []; while bal < 1000000 bal = 1.08*bal + 5000; year = year + 1; bal_vec = [bal_vec;bal]; end This is not the best practice, since the size of the "bal_vec" vector changes at each loop iteration. This likely will not cause any noticeable differences with small computations, but is not ideal. A better, slightly more complicated approach would be to preallocate a large vector, and then to trim it at the end. An example is shown below: bal = 5000; year = 0; bal_vec = zeros(1000,1); while bal < 1000000 bal = 1.08*bal + 5000; year = year + 1; bal_vec(year) = bal; end bal_vec = bal_vec(1:year); This makes it so that the space in memory is allocated, and therefore the vector is not changing size at each iteration. We also use the "year" as a natural counter (and index) to fill in the "bal_vec" vector. However, at the end, we have to trim the vector down to contain only the results. Otherwise, it would contain a lot of zeros. I hope this helps!
I wondered in real world terms ie. getting half a percent interest as in real bank accounts savings, and able to deposit 1000 a year to see how long it would take to get to a million dollars. Just have to live 359 years and I would have 1.0045e+06 dollars... while that is seriously depressing, I did find this a very helpful tutorial.
In Example 2 you have a mistake: The formula is only bal = 1.08*bel Otherwise you would earn 8% plus 5000 each year. That's why your money grows so fast. Actually it takes 69 years... Nevertheless thank you for the example.
I have a great teacher but I only have him once a weekl. You are saving my grade right now.
Glad to help!
Thanks for the great tutorial, you're much better than my lecturer!
At 2:37 how did you put % in the same time opal the beginning of the 4 lines?
@@Ivanwu-0324 on windows, I pressed ctrl+r to comment everything that is highlighted. There is also a key at the top of the screen that will do the same. It is labeled Comment.
i study naval engennering and matlab is a big part of the first years, thank you so much for the expalnations and all this confusion
My pleasure!
Your presentation and explanation is great.
Glad to help!
Excellent explanation!! Thanks for posting this video!!!
You're very welcome!
got midterm tomorrow(literally today), this video just give me 5 more points!
I hope it goes well!
Did it go well?
@@elcanaldegaming6677 it went great
Two questions:
1. At 1:17 you make the 3 lines "%" how do you do that?
2. how do you get that big letters?
Btw thanks for the video. really helped - this is actually easypeasy
I'm glad the video was helpful! To answer your questions:
1) In the editor, there is a button (under the "Edit" menu) called "Comment". You can highlight text and press the button, and it will comment the highlighted text out, or you can use a shortcut (Ctrl+r on Windows), which is what I did. To uncomment, there is also a button for that, or a shortcut (Ctrl+t on Windows), which is what I use.
2) To get big letters, or to change the font in general, in the command window, under the "Environment" menu, click on "Preferences". A new window will open, and in the left menu, select "Fonts". You should then see options for font type, text style, and text size. I used size 24 in the videos.
Well done! Very clear and concise, thank you.
My pleasure!
We all know how to become millionaires now!
I know, right? It's so simple :)
How would I use a while loop to check if the input is an integer?
Thanks! This is the kind of example I've been looking for.
You're welcome! Glad I could help!
Thanks this helped me finish my homework.
Let's say I want to store the balance in example 2 in a matrix - thus it would be a 36 x 1 matrix - how can I do that?
The easiest (though not the most proper) way to do this would be to declare an empty matrix before the loop, and to concatenate the next result to this matrix after every loop iteration. For example, something like this:
bal = 5000;
year = 0;
bal_vec = [];
while bal
Write the JavaScript to read a positive number from the user and then print
to the console the numbers from 1 to the user entered number.
Ex. If the user enters 50, you should print the numbers 1 to 50 in the
console.
This video is about MATLAB, not JavaScript. I could help you solve the problem in MATLAB, although I would use a for loop, not a while loop. For example, you could use:
x = input('Please enter a number: ');
for ii = 1:x
disp(ii);
end
So useful. thanks alot buddy!
My pleasure!
hi ive got a question, what is a(counter) and does sum_a equal 0 in every new loop and a(counter) just becomes 1,3,6,10... respectively to make the sum equal to 1,3,6,10...etc.?
The variable "a" is a vector, and "counter" is a scalar. Therefore, "a(counter)" is a given value of "a". For example, if "counter" = 5, then "a(counter)" = 5, since the 5th value of "a" is 5. The variable "sum_a" is keeping track of the current sum of the elements of "a". In every loop iteration, the next value of the vector "a" gets added to the running total in "sum_a". In general, no variable will become 0 at the start of a loop iteration unless it is explicitly declared to do so. Here, "sum_a" is only declared to be 0 once outside of the loop, and therefore its value will not be reset.
Thanks a lot! I actually find this tutorial really helpful. Before I saw this tutorial I was very confused about the structure of the while loop. Now I finally understand what is going on here...appreciate your help doc!
Thanks for the video,
it helped me lot.
I am curious to know, how you put a percentage sign to more than one line in a single click, can you tell me command you used??
I'm glad I could help! To comment multiple lines, you first highlight them. Then, there is a button at the top of the editor called "comment". Or if you are using Windows, you can click CTRL+r (and CTRL+t to uncomment). I hope this helps!
@@IlyaMikhelson Yes! Perfectly working, Thanks a lot.
I'm new to MATLAB, in case if I need any help I'll ask you, if you don't have any problem. 😊
The explanation was very clear, thank you!
However, I have a question about the example with money investment. Is there a possibility to get exactly the value < 1 mln dollars? I mean - how to make a while loop that wouldn't count the last, "excess" value. In this example, one can see that the final amount of money is above 1 mln dollars despite the condition for the loop. Is it only possible to, e .g. display the n-1 value to do it easily?
There are many ways to accomplish this, but I think that the following is more-or-less straightforward.
bal_old = 0;
bal_new = 5000;
year = 0;
while bal_new < 1000000
bal_old = bal_new;
bal_new = 1.08*bal_old + 5000;
year = year + 1;
end
disp(year-1)
disp(bal_old)
The idea is that we now have two "balance" variables, one to keep track of the new balance, and one to keep track of the previous balance. This way, when the new balance passes the threshold, we can always reference the previous balance. I hope this makes sense!
Thank you for your answer! It's easy and it works very well.
Hey I have a question: how can you make a while loop that repeats until a certain variable, vector L, does not change? I though about starting with "while K ~= L" and then put "K = L;" before the for-loop that changes L, but then the while-loop, of course, stops immediately.
(To be more specific, I have an assignment for which I need to write a function that implements the k-means algorithm.)
When you use a vector for the condition of a while loop, ALL elements must be true in order for it to execute. For example, "while [1 1 1]" will execute, whereas "while [1 0 1]" will not. Therefore, in your condition, ALL elements of K and L must have been different for the loop to keep running. Instead, you could use the "norm" function. You can then analyze the norm of the difference of the two vectors. For example, you could use "while norm(K-L) > 0", since you know that if the norm is not zero, then the vectors are not the same.
at 8:50 could u explain a(counter)??
I am assuming you are referring to the example at 6:05. Here, the variable "a" is a vector of values. The variable "counter" is our index. We go through each value in "a", one by one (by incrementing "counter" by 1 every iteration), and add that value to the running total ("sum_a"). I hope that makes sense.
this is fantastic. I am going to show this to my students, i am a lecturer at a university. Could i save the video and show it later, offline??
I'm glad you found it helpful! Please feel free to use it for educational purposes.
how do you put an or function in the while loop? specifically im trying to have the loop continue until the inputted value for a variable (a) is equal to one of three values. so for example until a is equal to 1 2 or 3 it will continue to prompt the user to input a valid value for a
The easiest way to do this is to use the OR operator (||). So you would have something like "while ~(a==1 || a==2 || a==3)". For more details on logical operators, check out my Logical Expression video. I hope this helps!
it is good for Basic While loop in Mathlab
explains very well
thanks for the helpful and clear explanation!
man I really love u . u make the life easier with Matlab , but if u don't mind, what's the difference between for loop and while I know if statments only used for bigger, smaller or qual to
Thank You. Just wanted to ask how do you store results in a vector for while loop? Because you wouldn't know what size zero vector to create before the while loop.
Harjinder Singh I apologize this response is so late. For a while loop, you could create a vector of zeros that would be large enough to accommodate any output your while loop could create (e.g. zeros(10000000,1)). Then, you can keep track of your iterations with a counter and trim off the end beyond the value of the counter. Alternatively, you could use dynamic allocation. For example, you could start with an empty vector (e.g. x=[]). Then, every time you want to store a new value y, use x = [x;y]. This concatenates the running x vector with the new value, and thus actively grows it as the program runs. I hope that helps!
hello, can matlab do infinite loop? like always show receive data from the input , thx
+Yvonne Chang You can absolutely do that. The exact structure would depend on the application. The easiest way would be to have something like "while 1", but then the only way to get out of the loop would be a forced exit. Alternatively, you can keep looping until the input is a particular value, for example the letter "q". I hope this helps!
+Ilya Mikhelson Thanks! i'll ask you later if i still don't understand, if you don't mind
I have a question. Why do need there '+5000' next to '1.08*bal'? I think '1.08*bal' contains deposit.
Multiplying by 1.08 only accounts for the interest rate, since it adds 8% of the current balance. Then, since we also want to include an independent deposit, we must add a separate value. I hope this clears things up!
+Ilya Mikhelson Okay, I see. Thanks!
How do turn what you've marked into "explanation format" so easy?(the green text with a % in front of it)
HotDaffodil In the editor, there is a button that says "Comment". You can highlight text and click it. In the video, I used the shortcut for it, which is "Ctrl + r" on a Windows computer.
Thanks! :D
Just curious how to use MATLAB to find the values of two symbols?
a+c=30 and 2
You could use a for loop and go through the possible values of a and c, keeping the results when both criteria are satisfied. For example:
a_vals = [];
for a = -10:40
for c = -10:40
if a+c==30 && c-a>=2 && c-a
It greatly helps, thank you.
Where do I put the function which a and c are calculated from?
The function works but give me integers from 10-14 (the interval that is set)
What's a(counter) ?
There is a formula for compound interest C=P(1+r)^n; where P= Principal/ Initial Amount; r= Rate of Interest; n= # of year.
In this case we have to find when our balance will reach 1,000,000? While it is given that initial amount is 5,000 and rate of interest is 8%.
Ans. In this case 5,000*(1+.08)^n >=1,000,000 => (1.08)^n >=200. So n >=68.84. So you need 69 years to surpass 1,000,000. After 69 years your balance will become $1012066.69.
But your program calculated it 36 years and 1,015,400. Make me correct if I am wrong.
Correct program should be
bal=5000;
year=0;
while (bal
Don't forget that I am also depositing $5000 each year!
i still don't understand this line of code - sum_a = sum_a + a(counter). specifically the a(counter) part. Sorry, if its a stupid question. But i have seen you do this in your for loops video. why can't i just use ''sum_a=sum_a + counter''. I get the same answer with you if i do this. And this makes more sense to me or maybe I still don't understand the a(counter) part.
+sola ade That's an excellent question. The reason I use a(counter) is to keep things as general as possible. The vector "a" can contain any values (not necessarily just 1, 2, 3, etc.), and the variable "counter" is a counter, which increments by 1 every loop iteration. The point, in general, is to use "counter" as an index into the vector "a" and use the next value in "a" for whatever operation you want to perform. In the example at 5:34, the vector "a" is just composed of incrementing values, so in effect, "a(counter)" is equal to "counter" itself. However, imagine if you want to add the values in the vector "a = [2 5 -4 3]". Then, "sum_a = sum_a + a(counter)" would give you very different results than "sum_a = sum_a + counter". This is because "sum_a = sum_a + counter" will always add "counter" to the running total, whereas "sum_a = sum_a + a(counter) will add the "counter"th value of the vector "a".
I hope this makes sense!
+Ilya Mikhelson Thank you so so much!. You couldn't have explained it better. You are a great tutor.
I love your teaching, how can I get or download 34 bus system cos I have search not get it
all throughout but I could not get it.thanks sir
+Taiwo Babatunde Thank you! I do not know what the "34 bus system" is, though. Could you please clarify?
i have a code for harmonic flow and power flow but i dont understand it.i want to know if you can be of help to run it the matlab because anytime i run it brings NaN
+Taiwo Babatunde I can help with general MATLAB concepts, but not with individual problems. If you have a general "while loop" question, I'd be happy to help.
best classes
Thanks!
Thanks for the help man, much appreicated :)
Thanks, helped a lot
Your For loop video and this saved my ass man! thanks soo much!!
I'm very glad to help!
subscribed...I got an A on the exam thanks to your vids..much appreciated man
That's awesome to hear!
A BIG THANK YOU
My pleasure!
By the way, do you know how i can get a vector of the results(the balance after every increment) using the while loop
The easiest method would be to declare an empty matrix, and to increase its size at each iteration by appending the current balance. An example is shown below:
bal = 5000;
year = 0;
bal_vec = [];
while bal < 1000000
bal = 1.08*bal + 5000;
year = year + 1;
bal_vec = [bal_vec;bal];
end
This is not the best practice, since the size of the "bal_vec" vector changes at each loop iteration. This likely will not cause any noticeable differences with small computations, but is not ideal. A better, slightly more complicated approach would be to preallocate a large vector, and then to trim it at the end. An example is shown below:
bal = 5000;
year = 0;
bal_vec = zeros(1000,1);
while bal < 1000000
bal = 1.08*bal + 5000;
year = year + 1;
bal_vec(year) = bal;
end
bal_vec = bal_vec(1:year);
This makes it so that the space in memory is allocated, and therefore the vector is not changing size at each iteration. We also use the "year" as a natural counter (and index) to fill in the "bal_vec" vector. However, at the end, we have to trim the vector down to contain only the results. Otherwise, it would contain a lot of zeros.
I hope this helps!
I got the vector with the 2nd method, Thanks a lot...do you have videos on root finding using the newton-rhaphson and the bisection method
ohh and least squares fitting and interpolation
awesome!
Thanks!
Thanks!
My pleasure!
excellent
Cool 😎 thanks
I love you. Thank you so much.
thanks for the help
I wondered in real world terms ie. getting half a percent interest as in real bank accounts savings, and able to deposit 1000 a year to see how long it would take to get to a million dollars. Just have to live 359 years and I would have 1.0045e+06 dollars... while that is seriously depressing, I did find this a very helpful tutorial.
Mikej1592 Real life can be depressing, but the world of MATLAB is always happy :) Go ahead, set the interest rate to 20%!
In Example 2 you have a mistake:
The formula is only bal = 1.08*bel
Otherwise you would earn 8% plus 5000 each year. That's why your money grows so fast. Actually it takes 69 years...
Nevertheless thank you for the example.
At 3:21 I specify that we also deposit $5000 each year.
@@IlyaMikhelson Oh sorry, I missed that!
@@Jonas_s No worries!
you put the interest rate of 108% not 8% though
Don't forget that: 1.08*bal = (1 + 0.08)*bal = bal + 0.08*bal. Hence, we are adding 0.08*bal to the previous bal.
@@IlyaMikhelson you mean balance + interest plus saving of 5000 each year. I don’t think this will hit million dollar by 37 years
@@mB-mp6io Compounding returns truly are amazing :)
Can you not chew your gum while recording?
I have never chewed gum while recording...
I'm using Octave GNU. My fuck is it a piece of shit....
plz help
wtf is with your = sign?!!
dado i sako polumenta
Thank you for the tutorial. Faiz haram.
You're very welcome!