Too many input arguments

2 Ansichten (letzte 30 Tage)
Mathew
Mathew am 20 Feb. 2025
Kommentiert: Sam Chak am 21 Feb. 2025
clear all; close all;
syms k
z0=2; r=0.01; K=100;
t=0:20:500;
u=0.75; B=1;
H=@(r) B+r*(1+z0./K)*(u-1);
F=@(t) r*(1-z0./K)*u*t.^u;
z=(B*z0/H(r))* symsum((F(t)./H(r)).^k/gamma(k*u+1),k,0,20);
zfcn = matlabFunction(z);
figure
semilogy(zfcn(t))
Error using sym/matlabFunction>@()[2.005113038247531,1.0./sqrt(pi).*1.298420190275181e-2+1.863145905367271e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*4.825947247317249e-4)./pi+2.005120920720691,1.0./sqrt(pi).*3.672502285205008e-2+3.133454093356336e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*2.295625548121586e-3)./pi+2.005176098119577,1.0./sqrt(pi).*6.746894298713936e-2+4.24719856221843e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*5.716221725839784e-3)./pi+2.005325866110514,1.0./sqrt(pi).*1.038775353681554e-1+5.270206334681761e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.092009584808589e-2)./pi+2.005617522776865,1.0./sqrt(pi).*1.451785737172247e-1+6.230813465160406e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.804191350430131e-2)./pi+2.00609837140796,1.0./sqrt(pi).*1.908525940660575e-1+7.144672535509189e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*2.719275779710953e-2)./pi+2.006815724403713,1.0./sqrt(pi).*2.405200513865164e-1+8.021664372626287e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*3.846816503063656e-2)./pi+2.007816908295099,1.0./sqrt(pi).*2.938888891483324e-1+8.8685849809244e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*5.195259229838972e-2)./pi+2.009149269880756,1.0./sqrt(pi).*3.507263460178208e-1+9.690402512763223e-1./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*6.772219848946139e-2)./pi+2.010860183480125,1.0./sqrt(pi).*4.108422544893403e-1+1.049092107875898./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*8.584671431461699e-2)./pi+2.012997059303685,1.0./sqrt(pi).*4.740784362364065e-1+1.127316298296258./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.063907735051988e-1)./pi+2.015607352941042,1.0./sqrt(pi).*5.403016069420206e-1+1.203960364494845./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.294149034393167e-1)./pi+2.018738575967815,1.0./sqrt(pi).*6.093984311943063e-1+1.279232354188988./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.549762892889505e-1)./pi+2.022438307672529,1.0./sqrt(pi).*6.81271961165741e-1+1.353311060554923./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*1.831293813862405e-1)./pi+2.026754207904963,1.0./sqrt(pi).*7.558390022866188e-1+1.426353160774678./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*2.139263904658619e-1)./pi+2.031734031047712,1.0./sqrt(pi).*8.330281208911004e-1+1.498498336177004./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*2.474177005352459e-1)./pi+2.037425641113012,1.0./sqrt(pi).*9.127781090949674e-1+1.569873034774264./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*2.836522198514454e-1)./pi+2.043877027967258,1.0./sqrt(pi).*9.950367832429164e-1+1.640593294671798./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*3.226776844966032e-1)./pi+2.051136324685973,1.0./sqrt(pi).*1.079760030829041+1.710766901903874./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*3.645409250549535e-1)./pi+2.059251826042408,1.0./sqrt(pi).*1.166911045912215+1.780495066505609./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*4.092881041631715e-1)./pi+2.068272008133374,1.0./sqrt(pi).*1.256459709855619+1.849873743343589./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*4.569649307912908e-1)./pi+2.078245549146343,1.0./sqrt(pi).*1.348382085736601+1.918994686672854./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*5.076168557410078e-1)./pi+2.089221351272344,1.0./sqrt(pi).*1.442660002832661+1.987946302180176./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*5.612892518491288e-1)./pi+2.10124856376968,1.0./sqrt(pi).*1.539280713336618+2.056814342993479./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*6.180275816435302e-1)./pi+2.114376607184021,1.0./sqrt(pi).*1.638236607622093+2.125682484065596./gamma(3.0./4.0)+(sqrt(2.0).*gamma(3.0./4.0).*6.77877554642217e-1)./pi+2.128655198730981]
Too many input arguments.
grid on

Akzeptierte Antwort

Star Strider
Star Strider am 20 Feb. 2025
Plotting over ranges of ‘t’ and ‘u’ defines a surface, so create vectors for both of them, and use either ndgrid or meshgrid (the outputs are transposes of each other) to create the appropriately-sized matrices for those vectors. Then, create ‘zfcn’ as a function of both of them, and plot the result.
Try this —
clear all; close all;
syms k t u
z0=2; r=0.01; K=100;
% t=0:20:500;
% % u=0.75;
% u = 0.1:0.1:0.75;
% [T,U] = ndgrid(t,u);
B=1;
H=@(r) B+r*(1+z0./K)*(u-1);
F=@(t) r*(1-z0./K)*u*t.^u;
z(t,u) = (B*z0/H(r))* symsum((F(t)./H(r)).^k/gamma(k*u+1),k,0,20); % ‘z’ Is Now A Function Of Both ‘t’ and ‘u’ (NOTE: Appropriate Changes In The ‘syms’ Declaration)
zfcn = matlabFunction(z) % ‘zfcn’ Also Is Now A Function Of Both ‘t’ and ‘u’
zfcn = function_handle with value:
@(t,u)(((t.^u.*u.*9.8e-3)./(gamma(u+1.0).*(u.*1.02e-2+9.898e-1))+(t.^(u.*2.0).*u.^2.*1.0./(u.*1.02e-2+9.898e-1).^2.*9.604e-5)./gamma(u.*2.0+1.0)+(t.^(u.*3.0).*u.^3.*1.0./(u.*1.02e-2+9.898e-1).^3.*9.41192e-7)./gamma(u.*3.0+1.0)+(t.^(u.*4.0).*u.^4.*1.0./(u.*1.02e-2+9.898e-1).^4.*9.2236816e-9)./gamma(u.*4.0+1.0)+(t.^(u.*5.0).*u.^5.*1.0./(u.*1.02e-2+9.898e-1).^5.*9.039207968e-11)./gamma(u.*5.0+1.0)+(t.^(u.*6.0).*u.^6.*1.0./(u.*1.02e-2+9.898e-1).^6.*8.85842380864e-13)./gamma(u.*6.0+1.0)+(t.^(u.*7.0).*u.^7.*1.0./(u.*1.02e-2+9.898e-1).^7.*8.6812553324672e-15)./gamma(u.*7.0+1.0)+(t.^(u.*8.0).*u.^8.*1.0./(u.*1.02e-2+9.898e-1).^8.*8.507630225817856e-17)./gamma(u.*8.0+1.0)+(t.^(u.*9.0).*u.^9.*1.0./(u.*1.02e-2+9.898e-1).^9.*8.337477621301499e-19)./gamma(u.*9.0+1.0)+(t.^(u.*1.0e+1).*u.^10.*1.0./(u.*1.02e-2+9.898e-1).^10.*8.170728068875469e-21)./gamma(u.*1.0e+1+1.0)+(t.^(u.*1.1e+1).*u.^11.*1.0./(u.*1.02e-2+9.898e-1).^11.*8.00731350749796e-23)./gamma(u.*1.1e+1+1.0)+(t.^(u.*1.2e+1).*u.^12.*1.0./(u.*1.02e-2+9.898e-1).^12.*7.847167237348e-25)./gamma(u.*1.2e+1+1.0)+(t.^(u.*1.3e+1).*u.^13.*1.0./(u.*1.02e-2+9.898e-1).^13.*7.69022389260104e-27)./gamma(u.*1.3e+1+1.0)+(t.^(u.*1.4e+1).*u.^14.*1.0./(u.*1.02e-2+9.898e-1).^14.*7.53641941474902e-29)./gamma(u.*1.4e+1+1.0)+(t.^(u.*1.5e+1).*u.^15.*1.0./(u.*1.02e-2+9.898e-1).^15.*7.385691026454039e-31)./gamma(u.*1.5e+1+1.0)+(t.^(u.*1.6e+1).*u.^16.*1.0./(u.*1.02e-2+9.898e-1).^16.*7.237977205924958e-33)./gamma(u.*1.6e+1+1.0)+(t.^(u.*1.7e+1).*u.^17.*1.0./(u.*1.02e-2+9.898e-1).^17.*7.093217661806459e-35)./gamma(u.*1.7e+1+1.0)+(t.^(u.*1.8e+1).*u.^18.*1.0./(u.*1.02e-2+9.898e-1).^18.*6.95135330857033e-37)./gamma(u.*1.8e+1+1.0)+(t.^(u.*1.9e+1).*u.^19.*1.0./(u.*1.02e-2+9.898e-1).^19.*6.812326242398923e-39)./gamma(u.*1.9e+1+1.0)+(t.^(u.*2.0e+1).*u.^20.*1.0./(u.*1.02e-2+9.898e-1).^20.*6.676079717550945e-41)./gamma(u.*2.0e+1+1.0)+1.0).*2.0)./(u.*1.02e-2+9.898e-1)
t=0:20:500; % Previous Vector unchanged
% u=0.75;
u = 0.1:0.1:0.75; % New Vector
[T,U] = ndgrid(t,u); % Create Matrices
figure
% semilogy(zfcn(t))
surf(T, U, zfcn(T,U)) % Plot Surface
xlabel('t')
ylabel('u')
zlabel('z')
set(gca, 'ZScale','log') % Optional
colormap(turbo)
colorbar
You could also do this with fsurf with the symbolic function, although the results would likeely be a bit different.
See the documentation on the clim funciton to change the colour range.
.

Weitere Antworten (1)

Sam Chak
Sam Chak am 20 Feb. 2025
Previously, the symbolic t is undefined in the z(t) function.
clear all; close all;
syms k t
z0=2; r=0.01; K=100;
u=0.75; B=1;
H=@(r) B+r*(1+z0./K)*(u-1);
F=@(t) r*(1-z0./K)*u*t.^u;
z=(B*z0/H(r))* symsum((F(t)./H(r)).^k/gamma(k*u+1),k,0,20);
zfcn = matlabFunction(z)
zfcn = function_handle with value:
@(t)t.^3.*9.853089513345264e-10+t.^6.*2.420895258923788e-20+t.^9.*1.416218558303767e-31+t.^12.*3.163305726921127e-43+t.^15.*3.416357717856453e-55+t.^(3.0./2.0).*1.0./sqrt(pi).*1.451677034797244e-4+t.^(9.0./2.0).*1.0./sqrt(pi).*1.087011796854525e-14+t.^(1.5e+1./2.0).*1.0./sqrt(pi).*1.195313337499515e-25+t.^(2.1e+1./2.0).*1.0./sqrt(pi).*4.156566691246514e-37+t.^(2.7e+1./2.0).*1.0./sqrt(pi).*6.315066800643833e-49+(t.^(3.0./4.0).*1.97003436511362e-2)./gamma(3.0./4.0)+(t.^(1.5e+1./4.0).*3.218522944037243e-12)./gamma(3.0./4.0)+(t.^(2.7e+1./4.0).*5.147261113564229e-23)./gamma(3.0./4.0)+(t.^(3.9e+1./4.0).*2.295337998974923e-34)./gamma(3.0./4.0)+(t.^(5.1e+1./4.0).*4.202182874048589e-46)./gamma(3.0./4.0)+(sqrt(2.0).*t.^(9.0./4.0).*gamma(3.0./4.0).*5.705122037601079e-7)./pi+(sqrt(2.0).*t.^(2.1e+1./4.0).*gamma(3.0./4.0).*2.319627036455943e-17)./pi+(sqrt(2.0).*t.^(3.3e+1./4.0).*gamma(3.0./4.0).*1.829494074668569e-28)./pi+(sqrt(2.0).*t.^(4.5e+1./4.0).*gamma(3.0./4.0).*5.057055318288334e-40)./pi+(sqrt(2.0).*t.^(5.7e+1./4.0).*gamma(3.0./4.0).*6.446376853912875e-52)./pi+2.005113038247531
t=0:20:500;
figure
semilogy(t, zfcn(t))
grid on
  3 Kommentare
Torsten
Torsten am 20 Feb. 2025
Bearbeitet: Torsten am 20 Feb. 2025
z0=2; r=0.01; K=100;
T=0:20:500;
U=0.1:0.05:0.75;
B=1;
H = @(u) B+r*(1+z0/K)*(u-1);
F = @(t,u) r*(1-z0/K)*u*t^u;
Z = zeros(numel(T),numel(U));
for i = 1:numel(T)
t = T(i);
for j = 1:numel(U)
u = U(j);
Z(i,j) = 0.0;
for k = 0:20
Z(i,j) = Z(i,j) + (F(t,u)/H(u))^k/gamma(k*u+1);
end
Z(i,j) = Z(i,j)*B*z0/H(u);
end
end
surf(T,U,Z.')
zscale("log")
Sam Chak
Sam Chak am 21 Feb. 2025
@Torsten, Thank you for showing this approach.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by