Azzera filtri
Azzera filtri

plot function with parameters

1 visualizzazione (ultimi 30 giorni)
Yuriy Yerin
Yuriy Yerin il 12 Giu 2018
Commentato: Jan il 12 Giu 2018
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 Commento
Jan
Jan il 12 Giu 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by