MATLAB: How to calculate values at the nodal points

discretizationevaluation at the nodal points

hi!
Need to evaluate certain values at every nodal point. Have discretized then have used for loop to do calculation. Not getting any error but there is a variation in the result. My need is the value of P1,P2 ….. etc must be evaluated at each point. Do x_bar(j) represent the value of x_bar at the j th position (like x_bar(1)=0,x_bar(1)=0.01etc).
Xb = [0, .5, 1.25, 1.50];
delx_bar = [.01, .005, .0001];
x_bar = cumsum([Xb(1), repelem(delx_bar,diff(Xb)./delx_bar)]);
del_eta=0.02;
eta_inf=4;
n_xbar=length(x_bar);
eta=(0:del_eta:eta_inf).';
n_eta=length(eta);
for j=2:n_xbar-1
for i=2:n_eta
P1(j) = 1 - cos(x_bar(j));
P2(j) = 1 + cos(x_bar(j));
end
end

Best Answer

Xb = [0, .5, 1.25, 1.50];
delx_bar = [.01, .005, .0001];
x_bar = cumsum([Xb(1), repelem(delx_bar,diff(Xb)./delx_bar)]);
del_eta=0.02;
eta_inf=4;
n_xbar=length(x_bar);
eta=(0:del_eta:eta_inf).';
n_eta=length(eta);
P1 = zeros([],[]) ;
P2 = zeros([],[]) ;
for j=2:n_xbar-1
for i=2:n_eta
P1(i,j) = 1 - cos(x_bar(j));
P2(i,j) = 1 + cos(x_bar(j));
end
end