"Undefined function 'mtimes' for input arguments of type 'function_handle' " error comes up

1 vue (au cours des 30 derniers jours)
Danish Ahamed
Danish Ahamed le 20 Juin 2019
Commenté : Matt J le 23 Juin 2019
I am writing code and this error keeps popping up and I am not sure how to fix it:
clear all;clc;
syms x y
u1=@(x,y)(x/(x+y));
u2=@(x,y)(y/(x+y));
g12=@(u2)(0.218+0.276/(1+0.622*u2));
g13=1.517;
g23=0.3559;
dg1=diff(g12(u2),u2);
dg2=diff(g12(u2),2,u2);
du=u2-u1;
for z=0:0.1:1
G22=(1/x)+((1/y)*0.234)-2*g12+2*du*dg1+u1*u2*dg2;
G23=(1/x)-(g12+g13)+g23*0.234+u2*(u1-2*u2)*dg1+u1*u2*u2*dg2;
G33=(1/x)+((1/z)*0.000257)-2*g13-2*u2*u2*(1-u1)*dg1+u1*(u2^3)*dg2;
F=[G22*G33-G23*G23==0,x+y+z-1==0];
sol=solve(F,[x,y]);
disp('z=');
disp(z);
disp(double(sol.x));
disp(double(sol.y));
disp('-------------------------------------------------------------');
end
When I hit run it pops up with this error:
Undefined function 'mtimes' for input arguments of type 'function_handle'.
Error in @(u2)(0.218+0.276/(1+0.622*u2))
  2 commentaires
Star Strider
Star Strider le 20 Juin 2019
You must evaluate functions if you want to use them in calculations.
I am not certain what you are doing.
Since ‘u2’ requires two arguments, ‘g12’ needs to provide them:
g12=@(x,y)(0.218+0.276/(1+0.622*u2(x,y)));
This gets more complicated, because here:
dg1=diff(g12(u2),u2);
‘g12’ again requires two arguments, however you are only giving it one here, that being ‘u2’, and it apparently has only one output.
You need to decide what to do, and write your functions accordingly.
Danish Ahamed
Danish Ahamed le 20 Juin 2019
Thank you for your reply, here what indent to do was provide first and second derivatives of g12 with respect to u2 for G22,G23 and G33 which are functions of x,y and z while g12 is function of u2 only. since i have only 2 equation and 3 variabls to solve i considered z as constant and varied it in a for loop

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 21 Juin 2019
Modifié(e) : Matt J le 21 Juin 2019
Keep everything sym,
syms x y q %<---
u1=(x/(x+y));
u2=(y/(x+y));
g12= 0.218+0.276/(1+0.622*q); %<---
dg1=subs( diff(g12,q) , u2);
dg2=subs( diff(g12,2,q), u2);
g13=1.517;
g23=0.3559;
du=u2-u1;
for z=0:0.1:1
G22=(1/x)+((1/y)*0.234)-2*g12+2*du*dg1+u1*u2*dg2;
G23=(1/x)-(g12+g13)+g23*0.234+u2*(u1-2*u2)*dg1+u1*u2*u2*dg2;
G33=(1/x)+((1/z)*0.000257)-2*g13-2*u2*u2*(1-u1)*dg1+u1*(u2^3)*dg2;
F=[G22*G33-G23*G23==0,x+y+z-1==0];
sol=solve(F,[x,y]);
disp('z=');
disp(z);
disp(double(sol.x));
disp(double(sol.y));
disp('-------------------------------------------------------------');
end
  4 commentaires
Danish Ahamed
Danish Ahamed le 22 Juin 2019
Thanks Matt J,
Does not work fine one mine matlab(R2014a) as well as on a higher version(R2018a) and Matlab online All gives the same result as above. Could you please share the result you obtained.
Matt J
Matt J le 23 Juin 2019
Never mind. It didn't work.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by