MATLAB: How to run this code? I dont know what I am missing

code error

Indium Composition (Variable Definition)
Lattice Constans
cInGaN =5.2142 ; c0GaN = 5.1864; c0InN = 5.7033;
aInGaN = 3.2112; a0GaN = 3.1890; a0InN = 3.5378;
Stiffness Constants
C13InN =6; C13GaN = 15.8;
C33InN = 12.1; C33GaN = 18.2;
D = x*c0InN+(1-x)*c0GaN;
E = x*C13InN+(1-x)*C13GaN;
F = x*C33InN+(1-x)*C33GaN;
G = x*cInGaN+(1-x)*c0GaN;
H =(cInGaN-D)/D + 2*E*(aInGaN-G)/(F*G);
solve (H,x);

Best Answer

Try this to solve it numerically just by looking for the peak in H:
cInGaN =5.2142 ; c0GaN = 5.1864; c0InN = 5.7033;
aInGaN = 3.2112; a0GaN = 3.1890; a0InN = 3.5378;
C13InN =6; C13GaN = 15.8;
C33InN = 12.1; C33GaN = 18.2;
allx = linspace(-15, 10, 1000000);
for k = 1 : length(allx)
x = allx(k);
D(k) = x * c0InN+(1-x) * c0GaN;
E(k) = x * C13InN+(1-x) * C13GaN;
F(k) = x * C33InN+(1-x) * C33GaN;
G(k) = x * cInGaN+(1-x) * c0GaN;
H(k) =(cInGaN-D(k))/D(k) + 2 * E(k) * (aInGaN-G(k))/(F(k) * G(k));
end
plot(allx, D, '-', 'LineWidth', 2);
hold on;
plot(allx, E, '-', 'LineWidth', 2);
plot(allx, F, '-', 'LineWidth', 2);
plot(allx, G, '-', 'LineWidth', 2);
plot(allx, H, '-', 'LineWidth', 2);
grid on;
legend('D', 'E', 'F', 'G', 'H');
title('D, E, F, G, and H vs. x', 'FontSize', 20);
xlabel('x', 'FontSize', 20);
ylabel('D, E, F, G, or H', 'FontSize', 20);
H(H<0) = 0;
[peakValues, peakIndexes] = findpeaks(H)
allx(peakIndexes)
x1 = allx(peakIndexes(1)-1)
x2 = allx(peakIndexes(2)+1)
H(peakIndexes(1)-1)
H(peakIndexes(2)+1)
fprintf('H = 0 at x=%f and %f\n', x1, x2);
You'll see in the command window:
H = 0 at x=-10.033670 and 2.983618