"Undefined function 'mtimes' for input arguments of type 'function_handle' " error comes up
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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.
Réponses (1)
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
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!