Anonymous function of a series of nonlinear equations to accept vector input
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a series of nonlinear equations, written as an anonymous function handle that outputs a vector solution of each function and Im trying to input a vector of x1,x2,x3. For the sake of the the error in my code I simplified it dramatically, however I cannot seem to get the function to output my desired results.
f= @(x1,x2,x3) [x1.^3;x2.^2;x3.^2]
x=[1;1;1]
f(x')
"Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters"
1 Commento
Dyuman Joshi
il 21 Set 2023
The function you have defined expects 3 inputs -
f= @(x1,x2,x3) [x1.^3;x2.^2;x3.^2]
But you have provided only 1 input, so it gives error
x=[1;1;1]
f(x')
I don't know how you about this error - "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters"
Risposte (1)
Star Strider
il 21 Set 2023
Either:
f= @(x1,x2,x3) [x1.^3;x2.^2;x3.^2];
x=[1;1.2;1.3];
f(x(1),x(2),x(3))
or:
f= @(x) [x(1).^3;x(2).^2;x(3).^2];
x=[1;1.2;1.3];
f(x')
should work.
.
2 Commenti
Star Strider
il 21 Set 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Vedere anche
Categorie
Scopri di più su Matrix Computations in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!