i not able to find error..not getting right plot

clc;
clear all;
k=1;
g=0.01:.1:6;
lambda=2;
b=2;
c=1;
l=2;
for x=0.01:.1:6
T=[];
P=(0.5*lambda)/((b^(lambda*c))*gamma(c));
Q=(k^0.5)*l^(lambda*c-0.5)/((2*pi)^(0.5*(l+k)-1));
R=evalin(symengine, sprintf('meijerG([[1],[]], [[1,0.5],[]],%f)',x^2));
T=[T P*Q*R];
end
plot(g,T)

 Respuesta aceptada

dpb
dpb el 17 de Ag. de 2015
for x=0.01:.1:6
T=[];
...
T=[T P*Q*R];
end
plot(g,T)
You wipe out T every pass thru the loop so the result is simply the last P*Q*R computed. Move that outside the loop altho "growing" an array like this dynamically is not good practice; use preallocation and fill instead.
T=zeros(size(0.01:0.1:6)); % preallocate
ix=0; % array index
for x=0.01:0.1:6
...
ix=ix+1;
T(ix)=P*Q*R;
end
Or, use the loop for an integer variable and compute x dynamically as x=x+dx;

4 comentarios

khushi
khushi el 18 de Ag. de 2015
Editada: Walter Roberson el 18 de Ag. de 2015
I made changes according to u...but i forget to add one parameter...again getting error..plz help
clc;
clear all;
k=1;
g=0.01:.1:6;
lambda=2;
b=2;
c=1;
l=2;
T=zeros(size(0.01:0.1:6));
ix=0;
for x=0.01:.1:6
P=(0.5*lambda)/((b^(lambda*c))*gamma(c));
Q=((k^0.5)*l^(lambda*c-0.5)).*g.^(-lambda*c)/((2*pi)^(0.5*(l+k)-1));
R=evalin(symengine, sprintf('meijerG([[1],[]], [[1,0.5],[]],%f)',x^2));
ix=ix+1;
T(ix)=P*Q*R;
end
plot(g,T)
Your Q is now defined in terms of g, and your g is a vector, so your Q is now a vector for every iteration of x. Your P and R are scalars so P*Q*R is a vector the same length as g. You are trying to save that vector into the single element T(ix). Are you expecting a vector for each x value?
khushi
khushi el 18 de Ag. de 2015
Yes
In that case, you've got to allocated a square array instead of a vector and store into it...
T(ix,:)=P*Q*R;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 17 de Ag. de 2015

Comentada:

dpb
el 18 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by