Troubleshooting MATLAB Loops: Solving a Logmap Function Error

  • Thread starter elliottmarter
  • Start date
  • Tags
    Matlab
In summary, the individual is having trouble with an m-file in matlab that needs to loop and is looking for the necessary commands. The m-file calculates population size using the logistic mapping formula and needs to be looped a certain number of times. They have managed to find a solution before seeing a suggested code, but appreciate the help.
  • #1
elliottmarter
15
0
Hi guys, sorry if i didn't follow the template but its more of a quick query than proper laid out question, but it is part of my coursework...anyway here goes;

I'm having a bit of trouble with an m-file in matlab, i posted earlier but i appreciate that post was too vague for a response.

basically i have an m-file which goes like this

function [y]=logmap(lam, x)
%calculate population size, y, next year using:
%lam: effective growth rate of population (between 0-4)
x: current size of population
using the logistic mapping formula

y=lam*x*(1-x)


but what I really need is for it to loop, so that y goes back into it as the x value and then just keeps repeating it.
does anyone know the commands to make it do this, the "for" and "while" loops don't seem to have the right inputs for the situation, also i need to define a value, n, which is the amount of times i want it to loop.

can someone please give me a hand?
thanks
elliottmarter
 
Physics news on Phys.org
  • #2
Code:
function [y]=logmap(lam, x)
%calculate population size, y, next year using:
%lam: effective growth rate of population (between 0-4)
x: current size of population
using the logistic mapping formula

% Number of loops
n = 100;% Loop n times
for ii = 1:n
    x = lam*x*(1-x)
end

y = x;
end

Let me know if this helps
 
Last edited:
  • #3
this worked fine, but i managed a different solution before i saw your post, thanks all the same BerryBoy :)
 

1. How do I troubleshoot a MATLAB loop?

To troubleshoot a MATLAB loop, you can start by checking the syntax of your loop to ensure it is written correctly. Then, check the values being used within the loop to make sure they are appropriate for the task at hand. Additionally, you can use the debugging tools in MATLAB to step through the loop and identify any errors or issues.

2. What is a logmap function error in MATLAB?

A logmap function error in MATLAB occurs when there is an issue with the syntax or values used in a loop that is using the logmap function. This function calculates the logistic map, which is a mathematical equation often used in population dynamics and chaos theory.

3. Why am I getting an error when trying to solve a logmap function in MATLAB?

There are several potential reasons why you may be getting an error when trying to solve a logmap function in MATLAB. These could include incorrect syntax, using inappropriate values, or issues with the loop structure. It is important to carefully review your code and troubleshoot any potential issues.

4. How can I fix a logmap function error in MATLAB?

To fix a logmap function error in MATLAB, you can start by carefully reviewing your code and checking for any syntax errors. You can also try using different values within the loop to see if that resolves the issue. Additionally, using the debugging tools in MATLAB can help you identify and fix any errors in your code.

5. Can I use a different function instead of the logmap function in my loop?

Yes, you can use a different function instead of the logmap function in your loop. Depending on the task at hand, there may be other functions that are more appropriate or efficient to use. It is important to carefully consider your options and choose the best function for your specific needs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
940
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
955
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
917
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
Back
Top