SunnyD_
SunnyD_

Reputation: 21

Why is my code producing a 0's at the 11th Column

All of a sudden the 11th column of p is falling to zero and stays that way for the rest of the columns following it. I see no reason for this as the variables used to compute p do not change randomly.

clear all; clc; close all;


tic;

z1 = 1;
z1 = 2;
z2 = 2*z1;
z = [z1,z2];
la1 = 1/3;
la2 = 1/3;
la = [la1,la2];
z_ave = (z1*la2 + z2*la1)/(la1 + la2);
sigma = 0.75; 
theta = sigma/(sigma-1);
pe = 1.68;
xi = 0.01:0.01:0.2;

pe = linspace(1,1.5,100);
p = zeros(length(xi),length(pe))
for i = 1:20
    for j = 1:10
p(i,j) = (1+xi(i)*pe(j)^theta)^(1/theta)
end
end

plot(pe,p(1,:))

I expect the values to stay around 0.94 and lower, but there seems to be a problem.

Upvotes: -2

Views: 31

Answers (1)

Varun Kotian
Varun Kotian

Reputation: 21

You had a mistake in the for loops. Use 1:length(pe) instead of 1:10

clear all; clc; close all;


tic;

z1 = 1;
z1 = 2;
z2 = 2*z1;
z = [z1,z2];
la1 = 1/3;
la2 = 1/3;
la = [la1,la2];
z_ave = (z1*la2 + z2*la1)/(la1 + la2);
sigma = 0.75; 
theta = sigma/(sigma-1);
pe = 1.68;
xi = 0.01:0.01:0.2;

pe = linspace(1,1.5,100);
p = zeros(length(xi),length(pe));
for i = 1:length(xi)
    for j = 1:length(pe)
        p(i,j) = (1+xi(i)*pe(j)^theta)^(1/theta);
    end
end

plot(pe,p(1,:))

Upvotes: 2

Related Questions