Unrecognized function or variable in a code

10 次查看(过去 30 天)
% param value
clear all; close all;
% p is constant and q varies
k0 = 0.0000169; u=0.6; p=536.2; q=0.0000376;
% your function
k = @(t,u) (k0 + (p*k0.^u-q*k0).*t.^a/gamma(a+1) +(p*k0.^u-q*k0).*(p*u*k0.^u-q).*t.^(2*a)/gamma(2*a+1)...
+(p*k0.^u-q*k0).*((p*u*k0.^u-q).^2-p*u.*(u-1)*k0.^(u-1)./2).*t.^(3*a)/gamma(3*a+1));
% grid
%t = linspace(0,0.1);
%u = linspace(0.3,0.9);
%[T,U] = meshgrid(t,q);
t = linspace(0,0.1,50);
a = linspace(0.3,0.9,50);
[T,A] = meshgrid(t,a);
% evaluate function
Z = k(T,A);
Unrecognized function or variable 'a'.

Error in solution>@(t,u)(k0+(p*k0.^u-q*k0).*t.^a/gamma(a+1)+(p*k0.^u-q*k0).*(p*u*k0.^u-q).*t.^(2*a)/gamma(2*a+1)+(p*k0.^u-q*k0).*((p*u*k0.^u-q).^2-p*u.*(u-1)*k0.^(u-1)./2).*t.^(3*a)/gamma(3*a+1)) (line 6)
k = @(t,u) (k0 + (p*k0.^u-q*k0).*t.^a/gamma(a+1) +(p*k0.^u-q*k0).*(p*u*k0.^u-q).*t.^(2*a)/gamma(2*a+1)...
% plot
figure
surf(T,A,Z)
%surf(T,Q,Z,'facecolor','none')
xlabel('t');
ylabel('\mu');
zlabel('k(t)')

采纳的回答

Cris LaPierre
Cris LaPierre 2024-6-19
You create an anonymous function, k, that uses a variable a in the function. However, this variable was not defined at the time the anonymous function was defined.
  4 个评论
Steven Lord
Steven Lord 2024-6-19
% p is constant and q varies
k0 = 0.0000169; u=0.6; p=536.2; q=0.0000376;
k = @(t,a) (k0 + (p*k0.^u-q*k0).*t.^a./gamma(a+1) +(p*k0.^u-q*k0).*(p*u*k0.^u-q).*t.^(2*a)./gamma(2*a+1)...
+(p*k0.^u-q*k0).*((p*u*k0.^u-q).^2-p*u.*(u-1)*k0.^(u-1)./2).*t.^(3*a)./gamma(3*a+1));
% grid
t = linspace(0,1,50);
a = linspace(0.25,0.85,50);
[T,A] = meshgrid(t,a);
% evaluate function
Z = k(T,A);
% plot
figure
surf(T,A,Z)
xlabel('t');
ylabel('\alpha');
zlabel('k(t)')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by