Identify an unrecognized function or variable
Show older comments
clear all; close all;
syms T U t w
a=0.3; M=1; h0=1; h1=1; k0=1; k1=1; p=0.5; d=0.5; Z=10;
%t=0:1:10; %w=0.75;
H=@(s) (p*Z-d-exp(-s))*k1;
K=@(r,g) p*Z*k1-(d+exp(-r))*k1-2*exp(a*r).*g;
for n=1:10
y=int(H(U),0,10);
yy= h0 + ((1-a)./M)*H(t).*h1 + (a./M)*y;
h1=yy;
end
for n=1:10
z=int(K(U,T),0,10);
zz= k0 + ((1-w)./M).*K(t,yy).*k1 + (w./M)*z;
k1=zz;
end
zzfcn = matlabFunction(zz)
t=0:0.1:10;
w = 0.1:0.1:0.75;
[T,W] = ndgrid(t,w);
figure
surf(T, W, zzfcn(T,W))
xlabel('t')
ylabel('\omega')
zlabel('k(t)')
set(gca, 'ZScale','log')
colormap(turbo)
colorbar
Answers (1)
Note that the function zzfcn has three input variables: @(T,t,w)
Here is the corrected code:
clear all; close all;
syms T U t w
a=0.3; M=1; h0=1; h1=1; k0=1; k1=1; p=0.5; d=0.5; Z=10;
%t=0:1:10; %w=0.75;
H=@(s) (p*Z-d-exp(-s))*k1;
K=@(r,g) p*Z*k1-(d+exp(-r))*k1-2*exp(a*r).*g;
for n=1:10
y=int(H(U),0,10);
yy= h0 + ((1-a)./M)*H(t).*h1 + (a./M)*y;
h1=yy;
end
for n=1:10
z=int(K(U,T),0,10);
zz= k0 + ((1-w)./M).*K(t,yy).*k1 + (w./M)*z;
k1=zz;
end
zzfcn = matlabFunction(zz)
t=0:0.1:10;
w = 0.1:0.1:0.75;
[T,W] = ndgrid(t,w);
figure
surf(T, W, zzfcn(T, T,W))
xlabel('t')
ylabel('\omega')
zlabel('k(t)')
set(gca, 'ZScale','log')
colormap(turbo)
colorbar
11 Comments
a=linspace(0.1,0.1,0.95)
w=0.75;
a is empty, w has only one element. You can't use "plot3" in this case.
a=linspace(0.1,0.1,0.95)
What values for "a" do you want to set here ? At the moment, you set no values.
Mathew
on 10 Mar 2025
Walter Roberson
on 10 Mar 2025
Maybe
a = 0.1:0.1:0.95 ;
??
However, this will end at 0.9 not at 0.95
Walter Roberson
on 10 Mar 2025
for i=1:length(t)
y=int(H(U),0,10);
yy= h0 + ((1-w)./M).*H(t).*h1 + (w./M).*y;
h1=yy;
end
t is a vector.
yy involves H(t) where t is the entire t vector. So yy returns a vector the same size as the row vector t.
for i=1:length(t)
z=int(K(yy,t),0,10);
zz= k0 + ((1-w)./M).*K(yy,t).*k1 + (w./M).*z;
k1=zz;
end
yy is a vector, and t is a vector, and these are the same size. K(yy,t) is working with vectors.
K=@(g,s) p*Z*k1-(d+exp(-s))*k1-2*exp(a.*s).*g;
Working with two vectors the same size is okay in K, with a vector the same size being returned.
So the int(K(yy,t),0,10) is a vector. The loop is not changing yy or t during the iterations, so z will be the same each iteration.
Then zz involves computing with the vector K(yy,t) together with the vector z, so zz is going to end up being a vector the same size as t.
Except...
K involves computation with the vector a and the vector s and those vectors are not the same size, so you would generate an error in the computation exp(a.*s). Unless, that is, you deliberately made a the same size as t by using something such as
a = linspace(0.1, 0.95, numel(t));
Still, the loops over length(t) that use the entire vector t are suspicious. It would make more sense if you were to be doing something such as
for i=1:length(t)
y=int(H(U),0,10);
yy= h0 + ((1-w)./M).*H(t(i)).*h1 + (w./M).*y;
h1=yy;
end
and
for i=1:length(t)
z=int(K(yy,t(i)),0,10);
zz= k0 + ((1-w)./M).*K(yy,t(i)).*k1 + (w./M).*z;
k1=zz;
end
a=linspace(0.1,0.95,10);
?
It's important that t and a are both row vectors of equal size (here:10). Otherwise your code will not work.
Mathew
on 14 Mar 2025
Categories
Find more on Logical 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!