Effacer les filtres
Effacer les filtres

Unrecognized function or variable in a code

10 vues (au cours des 30 derniers jours)
Mathew
Mathew le 19 Juin 2024
Modifié(e) : Mathew le 19 Juin 2024
% 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)')

Réponse acceptée

Cris LaPierre
Cris LaPierre le 19 Juin 2024
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 commentaires
Steven Lord
Steven Lord le 19 Juin 2024
% 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 le 19 Juin 2024
Modifié(e) : Mathew le 19 Juin 2024
Thanks @ Steven Lord and @ Cris LaPierre

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by