Simplifying Matlab Programming: Need Help with Iterating for xtotal Value

  • MATLAB
  • Thread starter tactical
  • Start date
In summary, to calculate the value of x1, x2, x3, and x4 at the instant when i+j+k+q=1, use nested for-loops. However, this may result in a longer processing time due to the increase in time complexity.
  • #1
tactical
6
0
Programming in matlab. I have everything entered correctly, I just need help with iterating.
The program is similar to the following:

for i=0.1:0.99
calculates x1
for j=0.1:0.99
calculates x2
for k=0.1:0.99
calculates x3
for q=0.1:0.99
calculates x4
end
end
end
end
xtotal=x1*x2*x3*x4

I want to display all xtotal value, but the catch is I need i+j+k+q=1.
So for example i=.20,j=.25,k=.40,q=.15

TIA
 
Physics news on Phys.org
  • #2
It's not quite clear, but do you want to calculate the value of x1, x2, x3 and x4 at the instant when i+j+k+q=1? In that case, use nested for-loops.
Matlab:
for i=0.1:0.01:0.99
    for j=0.1:0.01:0.99
        for k=0.1:0.01:0.99
            for q=0.1:0.01:0.99
                if (i + j + k + q == 1)
                    %calculate x1, x2, x3, x4
                    %calculate xtotal
                end
            end
        end
    end
end
But let me warn you beforehand that the time complexity of your code will significantly increase due to the four nested loops.
 
Last edited:

1. What is a "simple problem" in scientific terms?

A simple problem in science refers to a problem that has a straightforward solution and can be solved using basic principles or methods. It is usually a problem that does not require advanced knowledge or techniques to solve.

2. How do I determine if my problem is simple or complex?

To determine if a problem is simple or complex, you should first break it down into smaller parts and assess the difficulty of each part. If the problem can be solved by applying basic principles and methods, it is likely a simple problem. However, if it requires advanced knowledge or techniques, it may be a complex problem.

3. What are some common techniques for solving simple problems?

Some common techniques for solving simple problems include trial and error, using mathematical equations or formulas, conducting experiments, and using logical reasoning. It is important to choose the most appropriate technique based on the nature of the problem.

4. Can a simple problem have more than one solution?

Yes, a simple problem can have multiple solutions. However, the solutions may differ in terms of efficiency or effectiveness. It is important to evaluate all possible solutions and choose the one that best fits the problem and meets the desired outcome.

5. How can I prevent simple problems from becoming more complicated?

To prevent simple problems from becoming more complicated, it is important to identify and address them as soon as possible. This can be done by regularly reviewing and assessing your work, seeking help or advice from colleagues or experts, and being open to making adjustments or changes as needed.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
121
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top