plot function with parameters

1 次查看(过去 30 天)
Yuriy Yerin
Yuriy Yerin 2018-6-12
评论: Jan 2018-6-12
Hello everybody. I'd like to plot the function y=y(x) which is defined by the expression
I wrote the code but in result I get the error "Matrix dimensions must agree.
Error in self_energy>@(t,z,n,x)1./(t.^3+z.^4.*x+n.^4) (line 14) fun1= @(t,z,n,x) 1./(t.^3+z.^4.*x+n.^4);
Error in self_energy>@(t)fun1(t,z,n,x) (line 15) y1=quadgk(@(t)fun1(t,z,n,x),0,100);
Error in quadgk/evalFun (line 330) fx = FUN(x);
Error in quadgk/f1 (line 348) [y,too_close] = evalFun(tt);
Error in quadgk/vadapt (line 249) [fx,too_close] = f(x);
Error in quadgk (line 188) [q,errbnd] = vadapt(@f1,interval);
Error in self_energy/Gamma_0 (line 15) y1=quadgk(@(t)fun1(t,z,n,x),0,100);
Error in self_energy>@(z)Gamma_0(z,n,x(i)) (line 5) R(i)=1./(x(i)+n.^4+quadgk(@(z)Gamma_0(z,n,x(i)),0,10));
Error in quadgk/evalFun (line 330) fx = FUN(x);
Error in quadgk/f1 (line 348) [y,too_close] = evalFun(tt);
Error in quadgk/vadapt (line 249) [fx,too_close] = f(x);"
Here the code
function z1=self_energy
x=linspace(0,10,100);
for i=1:100
n=1:10;
R(i)=1./(x(i)+n.^4+quadgk(@(z)Gamma_0(z,n,x(i)),0,10));
y(i)=sum(R(i));
end
plot(x,y)
function y1=Gamma_0(z,n,x)
fun1= @(t,z,n,x) 1./(t.^3+z.^4.*x+n.^4);
y1=quadgk(@(t)fun1(t,z,n,x),0,100);
end
end
Could you help to understand me what I do in wrong way?
  1 个评论
Jan
Jan 2018-6-12
If you use functions instead of anonymous functions, it would be much easier to debug the code. Then a simple dbstop if error would be enough to let Matlab stop at the error, such that you can check the sizes of the variables.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by