How can I plot this equation?

1 回表示 (過去 30 日間)
Moj
Moj 2013 年 8 月 21 日
I want to plot a figure but I don't know how to write "s" string with a loop. Here is my code
k1=5.3e-12;
k3=7.3e-12;
mu=pi*4e-7;
kapa=9.56e-7;
theta_m1 = 0;
theta_m2 = 0.44;
for theta_m= theta_m1:0.1:theta_m2
fun = @(x)(((k1*cos(x).^2 + k3*sin(x).^2)./(sin(theta_m)^2-sin(x).^2)).^0.5);
s(:) = integral(fun,0,theta_m);
end
for theta_m= theta_m1:0.1:theta_m2
plot((mu/kapa)^0.5 *(2/1e-6)* s(:) ,radtodeg(theta_m))
hold on
end

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 8 月 21 日
thetas = theta_m1 : 0.1 : theta_m2
for K = length(thetas)
theta_m = thetas(K);
fun = @(x)(((k1*cos(x).^2 + k3*sin(x).^2)./(sin(theta_m)^2-sin(x).^2)).^0.5);
s(K) = integral(fun,0,theta_m);
end
  2 件のコメント
Moj
Moj 2013 年 8 月 21 日
But why can't this code plot this equation?
Walter Roberson
Walter Roberson 2013 年 8 月 21 日
Leave out the "for" loop around the plot
plot((mu/kapa)^0.5 *(2/1e-6)* s(:) ,radtodeg(theta_m))
Are you asking why your original code did not plot? It is because you overwrote all of s each time through your loop.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by