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

3 views (last 30 days)
Mohammed Najmi on 30 Jun 2020
Commented: Mohammed Najmi on 1 Jul 2020
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);

Mohammed Najmi on 30 Jun 2020
H should equal 0 and I want to solve for x
Geoff Hayes on 30 Jun 2020
Perhaps you need to define x as a syms like
syms x
cInGaN =5.2142 ; c0GaN = 5.1864; c0InN = 5.7033;
aInGaN = 3.2112; a0GaN = 3.1890; a0InN = 3.5378;
% etc.
Unfortunately, I don't have experince with the Symbolic Toolbox so can't say for certain if the above will help.
Image Analyst on 30 Jun 2020
I'm not sure I understand. For any x you give it, you get various values for D, E, F, G, and H, so what is there so solve for?
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, 100);
for k = 1 : 100
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);
You say you're trying to solve for x, so in the above plot, which value of x do you think would be the solution you are seeking? There are 4 x values where H is zero. Do you want them all? If so try ismembertol().

Image Analyst on 30 Jun 2020
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

Mohammed Najmi on 1 Jul 2020
I am really grateful for your support.
Image Analyst on 1 Jul 2020
Just change the limits in linspace() to include -186.56 and you'll see it.
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(-200, 10, 100000);
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);
fprintf('Done running %s.m.\n', mfilename);
Mohammed Najmi on 1 Jul 2020
Wonderful!! Thank you sooo much!!!!