Too many input arguments
1 回表示 (過去 30 日間)
古いコメントを表示
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))
grid on
0 件のコメント
採用された回答
Star Strider
2025 年 2 月 20 日
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’
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.
.
0 件のコメント
その他の回答 (1 件)
Sam Chak
2025 年 2 月 20 日
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)
t=0:20:500;
figure
semilogy(t, zfcn(t))
grid on
3 件のコメント
Torsten
2025 年 2 月 20 日
編集済み: Torsten
2025 年 2 月 20 日
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")
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!