New to MATLAB so need help with following
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given the following equation,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227105/image.png)
Given, d0=0.1 & d1=0.01 and model depends on value of b.
Now for b = 0.1, 0.2, 2.3, 2.6, 3, I am asked to find the largest proper value of xn for each of these values of b.
xn is said to be proper when xn+1 is nonnegative.
I am also asked to find a formula for largest proper value of xn in terms of b.
Can anyone help me with the syntax I need to do this? There are many more situations I need to consider but if I can get this one syntax, I will be able to understand the rest.
Also for context I have no clue how to start this. My professor suddenly gave me this and we haven't been taught MATLAB yet. This is only part of the question so if someone could provide how to do this one, I will be able to figure out the rest 4 questions. Thank you.
5 commentaires
Bob Thompson
le 2 Juil 2019
I cannot speak absolutely for John, but I suspect he is bothered by the apparent deception of the situation. The question, which is a duplicate, can be found here. Both answers there, and my own answer here, provide a reasonable foundation to build on. If you do not understand what are trying to get at then we are always available to answer questions, but we tend to be more forthcoming when we see that the person asking the question has put in effort to understand what is going on.
In short, this forum is not for us to write code for you. We are here to help bring guidance and answer questions. If you have no foundation in Matlab I strongly advise that you get ahold of some tutorials to teach you the basic syntax and commands you will need before asking further questions here. I'm not saying that because we don't want to answer questions, but because if you don't understand even the basic syntax then our answers will not make any sense, and be unhelpful. It is simply a language barrier problem. If I don't know any Greek, but I ask somebody how to make a statement in Greek, then it will not be very helpful when I get a response in Greek, because I have no idea what any of it means.
Réponses (1)
Bob Thompson
le 1 Juil 2019
For the most part, the syntax on this is pretty straight forward. The equation itself will look very similar to how it is written there.
I'm not entirely sure if you are looking for the largest value of xn that is proper, or if you are looking for the largest value of n, but the following should generally cover both situations. It is going to be a pretty basic setup, so it should be easy to follow. There are probably more advanced ways of determining this, but if you don't know anything about Matlab, I would suggest you start with this.
d = [0.1 0.01]; % Defining constants
b = [0.1 0.2 2.3 2.6 3]; % Defining all possible values of b
sets = nan(length(b),2); % Initialize blank value to store results
for i = 1:length(b) % Loop through all values of b
B = b(i); % Set value for this loop
xn = 1; % Set an initial value of xn, because you kind of need it. Replace as needed
n = 0; % Initialize value of n
while xn ~< 0 % Run until xn becomes negative
xnp = xn; % Record previous value of xn
xn = xn + B*xn - d(1)*xn - d(2)*xn^2;
% Calculate xn+1
n = n + 1; % Advance value of n
end
sets(i,:) = [xnp, n-1]; % Record results
end
2 commentaires
Bob Thompson
le 2 Juil 2019
I suggest looking up logical operators here. Most likely xnp is not defined because the loop is triggering false immediately, and xnp has not been defined because the loop has not run.
Voir également
Catégories
En savoir plus sur Labels and Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!