Define secondary variables based on main variables in fsolve
1 view (last 30 days)
Show older comments
Louis Nguyen
on 17 Aug 2022
Commented: Star Strider
on 18 Aug 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 Comments
Accepted Answer
Star Strider
on 17 Aug 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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!