I am writing a program in MATLAB to solve for the efficiency of a diesel engine based off of it's cutoff ratio.
I also need to plot efficiency vs cutoff ratio for a varying cutoff ratio from 1.3 to 2.8.
T1, P1, and r are user input and cp and k are constants.
The error message I keep getting says that the index is invalid. "Array indices must be positive integers or logical values."
for rc = 1.3:0.01:2.8
[P2, N, qin, T3, T4, P3, P4, wnet] = part_1(P1, k, cp, rc, r, T1);
i = i + 1;
y(i, :) = rc
x1(:,i) = N
title('Efficiency vs Cutoff Ratio')
Here is my function:
function [P2, N, qin, T3, T4, P3, P4, wnet] = part_1(P1, k, cp, rc, r, T1)
N = 1 - (1/r^(k-1))*((rc^k-1)/(k*(rc-1)));
T2 = T1*r^(k-1);
P2 = P1*r^k;
P3 = P2;
T3 = T2*rc;
T4 = T3*(rc/r)^(k-1);
P4 = P2*T2*(1/r);
qin = cp*(T3-T2);
wnet = N*qin;