plot function with parameters

조회 수: 3 (최근 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