Plotting a non-linear graph in Matlab

Hi guys,
I have this equation f(g)=1+cos(g)*cosh(g)-a*g*(cos(g)*sinh(g)-sin(g)*cosh(g))=0. I am trying to plot it for (a,g).
I have the initial condition that when a=0 then g=1.8751.
I am not sure how to code it as an equation with two unknowns and two initial values ??
My suggestion would be to plot the graph by using the solve function by using a=a+da (where da is small increment of a) and using the previous value of g as an initial value to find g for the new value of a.
Regards, Rihab

3 件のコメント

Muhammad Usman Saleem
Muhammad Usman Saleem 2016 年 10 月 15 日
編集済み: Walter Roberson 2016 年 10 月 16 日
f(g)=1+cos(g)*cosh(g)-a*g*(cos(g)*sinh(g)-sin(g)*cosh(g))=0.
there are two equality sign in this equation write correct one plz
Rihab el-Wali
Rihab el-Wali 2016 年 10 月 15 日
@Muhammad Usman Saleem I did mean to put two equal signs because the function is equal to zero. I want to plot (a,g) when f(g)=0.
Muhammad Usman Saleem
Muhammad Usman Saleem 2016 年 10 月 15 日
good night, tomorrow will guide u in this regards

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

 採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 16 日

1 投票

a = linspace(-4, 2); %the interesting part of the graph
g = zeros(size(a));
oldguess = 1.8751;
for K = 1 : length(a)
fa = @(g) 1+cos(g)*cosh(g)-a(K)*g*(cos(g)*sinh(g)-sin(g)*cosh(g));
this_g = fzero(fa, oldguess);
g(K) = this_g;
oldguess = this_g;
end
plot(a, g)
However, there are many solutions. You will, for example, get a different plot if you start with oldguess = 50

1 件のコメント

Rihab el-Wali
Rihab el-Wali 2016 年 10 月 16 日
That works! However, what if I want to plot for a larger range of a? When I change the vector size from [-4,2] to [0,100] the plot seems to look different.

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

その他の回答 (1 件)

Star Strider
Star Strider 2016 年 10 月 15 日
編集済み: Star Strider 2016 年 10 月 15 日

2 投票

When in doubt, plot first:
[A,G] = meshgrid(-0.5:0.01:0.5, -20:0.1:20);
fga = @(a,g) 1+cos(g).*cosh(g)-a.*g.*(cos(g).*sinh(g)-sin(g).*cosh(g))
F = fga(A,G);
figure(1)
meshc(A, G, F)
grid on
There appear to be a possibly infinite number of solutions. Which one do you want?

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by