Solving 3 Non-Linear Equations with Fsolve and FOR Loops

  • Thread starter Thread starter ethaniell
  • Start date Start date
  • Tags Tags
    For loops Loops
Click For Summary
SUMMARY

The discussion focuses on using MATLAB's fsolve function to solve three non-linear equations for three variables while varying a parameter from 1 to 5. The user attempts to store the results in a matrix format, with each row representing a variable and each column corresponding to the parameter variations. The user encounters errors when trying to store results, indicating a need for proper matrix initialization and indexing. The solution involves ensuring that the matrix is correctly defined before the loop and that results are stored appropriately within the loop.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of non-linear equations and their solutions
  • Knowledge of the fsolve function in MATLAB
  • Basic matrix operations in MATLAB
NEXT STEPS
  • Research MATLAB fsolve documentation for detailed usage and examples
  • Learn about matrix initialization techniques in MATLAB
  • Explore error handling in MATLAB to troubleshoot common issues
  • Investigate parameter sweeping techniques for optimization problems
USEFUL FOR

Mathematics students, engineers, and researchers who are solving non-linear equations using MATLAB, particularly those looking to understand parameter sensitivity and result storage in iterative computations.

ethaniell
Messages
2
Reaction score
0
Hi
I'm using the fsolve method to solve for 3 variables in 3 non-linear equations.
I would like to find out, how the 3 variables change, when I change a parameter in the 3 equations. Let's assume the parameter runs from 1 to 5 (1:1:5).

The iteration looks like this:
c=(1:5);
for i = 1:5
x = fsolve(@(x) myfun(x,c(i)),[1;1;1]);

end
I would like to store the results in a matrix, with the rows being each one of the three variables I solve for, and the columns being the variations in the parameter c.
I have tried the usual methods for storing, but it does not work with the fsolve, it always gives me an error.
Does anyone know how can I do it?
Thank you!
 
Physics news on Phys.org
What is the error?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
28K
  • · Replies 2 ·
Replies
2
Views
2K