MATLAB Answers

0

New to MATLAB so need help with following

Asked by Muhammad Islam on 1 Jul 2019
Latest activity Commented on by Bob Nbob
on 2 Jul 2019
This question was flagged by Jan
Given the following equation,
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 Comments

Why did you post the same question multiple times? The first time got answers. Anyway, stop posting your homework. Answers is not here to do your homework for you. If you want help, then show you have made an effort.
Umm while the title is the same the other question is a different one. I posted two different questions with the same title. Also, since I do not have a clue where to start I asked. As long as someone can even help with where to start I am good.
Also, in case you don't want to answer that is cool. Why get bothered?
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.

Sign in to comment.

1 Answer

Answer by Bob Nbob
on 1 Jul 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 Comments

Hi! First of all thank you! But there are some errors:
Firstly if I run the syntax as is, it shows the following:
while xn ~< 0 % Run until xn becomes negative
Error: Invalid use of operator.
Now I tried it by deleting the "~"
Then it shows:
Undefined function or variable 'xnp'.
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.

Sign in to comment.