# solving two-variable matrix function

4 vues (au cours des 30 derniers jours)
Dmitry Solomatin le 14 Déc 2022
Commenté : Jiri Hajek le 14 Déc 2022
Hi,
so assume I have a function like this:
f = [x(1) + x(2) ; x(2) * x(1)]
and my x = [2; -2]
how can I solve it? feval doesnt work for some reason ("Dimensions of arrays being concatenated are not consistent)
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Jiri Hajek le 14 Déc 2022
Hi this can be done using inline function very efficiently like this:
fh=@(x,y)[x+y,x*y];
fh(2,-2)
ans = 1×2
0 -4
##### 2 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Jiri Hajek le 14 Déc 2022
This is because Matlab interprets space within brackets as a separator of vector elements, same as a comma. You can eithertake away all the spaces or put your expressions into parentheses. That way, you can forget about the meaning of spaces:
fh = @ (x,y) [(2*x- 400*x*(-x^2+y) -2), (200 * (y-x^2))]
fh = function_handle with value:
@(x,y)[(2*x-400*x*(-x^2+y)-2),(200*(y-x^2))]
fh(2,-2)
ans = 1×2
4802 -1200

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!