Define secondary variables based on main variables in fsolve
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Louis Nguyen
le 17 Août 2022
Commenté : Star Strider
le 18 Août 2022
Hi,
I'm trying to use fsolve to solve a system of non-linear equations. The final equations invovles several intermeditary new variables. These new variables are defined based on the main variables whose roots are of intrest. An example is below where "a" is such intermeditary variable:
fun = @NELF;
x0 = [1, 1];
sol = fsolve(fun,x0)
function F=NELF(x1, x2)
a = x1 * 2;
F(1) = a * x1 - x2;
F(2) = x1 + x2 + 5;
end
However, running this code gives me the matrix multiplication error:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use '.*'.
Error in test2>NELF (line 10)
F(1) = a * x1 - x2;
Could you kindly advise how to overcome this error whist still defining a new variable "a" in this way?
Thanks a million!
0 commentaires
Réponse acceptée
Star Strider
le 17 Août 2022
The ‘NELF’ argument needs to be a vector. Also MATLAB is case-sensitive so I made all the vector references capital ‘X’ since they were mixed previously.
fun = @NELF;
x0 = [1, 1];
sol = fsolve(fun,x0)
function F=NELF(X)
a = X(1) * 2;
F(1) = a * X(1) - X(2);
F(2) = X(1) + X(2) + 5;
end
The fsolve function is a root-finding function. It apparently did not find any aero-crossings near the initial parameter estimates.
.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!