plot function with parameters
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everybody. I'd like to plot the function y=y(x) which is defined by the expression
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191204/image.jpeg)
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 comentario
Jan
el 12 de Jun. de 2018
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.
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!