フィルターのクリア

Unrecognized function or variable in a code

10 ビュー (過去 30 日間)
Mathew
Mathew 2024 年 6 月 19 日
編集済み: Mathew 2024 年 6 月 19 日
% 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)')
Mathew
Mathew 2024 年 6 月 19 日
編集済み: Mathew 2024 年 6 月 19 日
Thanks @ Steven Lord and @ Cris LaPierre

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by