Define secondary variables based on main variables in fsolve
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Louis Nguyen
el 17 de Ag. de 2022
Comentada: Star Strider
el 18 de Ag. de 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 comentarios
Respuesta aceptada
Star Strider
el 17 de Ag. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!