Borrar filtros
Borrar filtros

Unrecognized function or variable in a code

10 visualizaciones (últimos 30 días)
Mathew
Mathew el 19 de Jun. de 2024
Editada: Mathew el 19 de Jun. de 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)')

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 19 de Jun. de 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 comentarios
Steven Lord
Steven Lord el 19 de Jun. de 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 el 19 de Jun. de 2024
Editada: Mathew el 19 de Jun. de 2024
Thanks @ Steven Lord and @ Cris LaPierre

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by