Iterative method-Problems with array of symbolic functions
显示 更早的评论
Hello everyone.
I'm trying to write a code for an iterative method, using symbolic functions, but I have this error when I try to plot:
Error using fplot>singleFplot (line 240). Input must be a function or functions of a single variable.
I think that the problem can be related on the way I am using the sym arrays to store these functions or in the way I am calculating the convolution of sym functions (it is the only part of the code where i use a function of more than 1 variable).
Do you know if these is a more effective way to write the convolution?
Here is the code:
N=5;
k=0.01;
syms x y;
E = sym(zeros(N,1));
L = sym(zeros(N,1));
F = sym(zeros(N,1));
f(x,y)=-sqrt(3)/pi*sinh(2*x-2*y)/sinh(3*x-3*y);
A=2*log(2/k);
E(1)=k*cosh(y);
figure(); hold on
for i=1:3
L(i)=log(1+exp(-E(i)));
F(i)=int(f(x,y)*L(i),y,-A,A); %convolution
E(i+1)=E(1)+F(i);
if i==3
fplot(L(i),[-10,10]);
break;
else
continue;
end
end
hold off
Thank you very much.
--------------------EDIT-------------------------
I've changed the method to perform the convolution, and now I don't have errors anymore.
If I plot L(1) (see below) no problems, but when I try to plot L(i) (for example L(3)) I have an empty graph. Maybe there are still some problems when I try to fill the L array?
N=5;
k=0.01;
syms x y w;
E = sym(zeros(N,1));
L = sym(zeros(N,1));
f(x)=-sqrt(3)/pi*sinh(2*x)/sinh(3*x);
g(w)=fourier(f);
A=2*log(2/k);
E(1)=k*cosh(x);
figure(); hold on
for i=1:3
L(i)=log(1+exp(-E(i)));
h(w)=fourier(L(i));
l(w)=g*h;
s(x)=ifourier(l);
E(i+1)=k*cosh(x)+s;
if i==3
%fplot(L(1),[-10,10]); %This works
fplot(L(i),[-10,10]); %Doesn't work
break;
else
continue;
end
end
hold off
2 个评论
Star Strider
2019-12-14
The ‘L’ function is a function of x and y. Trying to plot it with fplot throws an error reflecting that, and it is seenttially impossible to plot it with fsurf.
It would likely be much more efficient to do this numerically and avoid the Symbolic Math Toolbox.
I cannot figure out from your code what you want to do.
Tommaso Franzini
2019-12-14
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Code Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!