Define secondary variables based on main variables in fsolve
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Louis Nguyen
il 17 Ago 2022
Commentato: Star Strider
il 18 Ago 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 Commenti
Risposta accettata
Star Strider
il 17 Ago 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Systems of Nonlinear Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!