Define secondary variables based on main variables in fsolve

5 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Star Strider
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)
No solution found. fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the value of the function tolerance.
sol = 1×2
-0.2500 -2.3125
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.
.

Más respuestas (0)

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by