Too many input arguments
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 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’
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 Comments
More Answers (1)
Sam Chak
on 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)
t=0:20:500;
figure
semilogy(t, zfcn(t))
grid on
3 Comments
Torsten
on 20 Feb 2025
Edited: Torsten
on 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")
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!