Unrecognized function or variable in a code
3 次查看(过去 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);
% plot
figure
surf(T,A,Z)
%surf(T,Q,Z,'facecolor','none')
xlabel('t');
ylabel('\mu');
zlabel('k(t)')
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!