I really with a MATLAB iteration code

In summary, a student is seeking help with writing a MATLAB code to solve a formula where k is a constant. They have attempted a fixed point iteration but it did not work and they need to submit their project to their professor in an hour. They are asking for assistance and grateful for any help.
  • #1
physicist10
17
0

Homework Statement



Hello, I want to obtain a solution to a, where k is a constant. The formula is:

k/a = tan(a)

I need to write a MATLAB code for this but I have been struggling for hours. And I must send the project to my professor in an hour. :(

Homework Equations



I know that I need to do an iteration but how? I tried doing a fixed point iteration but it didn't work.

The Attempt at a Solution



Very limited so far. I would be so so grateful for any help! Thanks!
 
Physics news on Phys.org
  • #2
physicist10 said:

Homework Statement



Hello, I want to obtain a solution to a, where k is a constant. The formula is:

k/a = tan(a)

I need to write a MATLAB code for this but I have been struggling for hours. And I must send the project to my professor in an hour. :(

Homework Equations



I know that I need to do an iteration but how? I tried doing a fixed point iteration but it didn't work.

The Attempt at a Solution



Very limited so far. I would be so so grateful for any help! Thanks!

You need to show us what you have done so far. We do not do your work for you here.
 

FAQ: I really with a MATLAB iteration code

1. How do I create an iteration code in MATLAB?

To create an iteration code in MATLAB, you can use a for loop or a while loop. For a for loop, use the syntax: for i = 1:n, where n is the number of iterations. For a while loop, use the syntax: while condition, where the loop will continue as long as the condition is true.

2. How do I update variables in an iteration code?

To update variables in an iteration code, you can use the assignment operator (=) to assign a new value to the variable. For example, x = x + 1 will update the variable x by adding 1 to its current value.

3. How do I control the number of iterations in my code?

To control the number of iterations in your code, you can use a for loop and specify the number of iterations using the loop index. For example, if you want 10 iterations, you can use the syntax: for i = 1:10. You can also use a while loop and include a counter variable that increments with each iteration, and use a condition to stop the loop after a certain number of iterations.

4. Can I use if statements in an iteration code?

Yes, you can use if statements in an iteration code to add conditional statements or actions. You can use the syntax: if condition, and include the desired actions or statements within the if statement block. You can also use else and elseif statements to add additional conditions.

5. How can I debug my iteration code if it is not working correctly?

To debug your iteration code, you can use the MATLAB debugger tool. You can set breakpoints in your code and run it step-by-step to see where errors or unexpected behavior may be occurring. You can also use the disp() function to print out the values of variables at different points in your code to help identify any issues.

Similar threads

Replies
4
Views
2K
Replies
12
Views
1K
Replies
27
Views
2K
Replies
5
Views
2K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
32
Views
3K
Back
Top