Plot the graph using non linear equation

3 ビュー (過去 30 日間)
Sun Heat
Sun Heat 2022 年 5 月 5 日
コメント済み: Rik 2022 年 5 月 5 日
Hey guys...
I have to plot the graph between "theta Vs h" value?
theta=linspace (30,90,7);
period=0.562;
k=(2.*pi)./(period.*sin(theta));
F=solve ((cos (theta). * (sin (k. h)). ^2) - (2. *(sin (k. *h. *cos (theta)). ^2)) == 0);
Thanks in advance
  1 件のコメント
Sun Heat
Sun Heat 2022 年 5 月 5 日
i want to plot 'h' for different value of theta

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

採用された回答

Chunru
Chunru 2022 年 5 月 5 日
It seems that you are solve equations of h for different parameters theta. You can solve the equation one by one.
Don't add space between the array operator ".*"
Your equation has an solution of h=0. Check your problem definition.
syms h
theta=linspace (30,90,7);
period=0.562;
k=(2.*pi)./(period.*sin(theta));
y = zeros(size(theta));
for i=1:length(theta)
F=vpasolve ((cos(theta(i)) * (sin(k(i)*h)).^2) - (2*(sin(k(i)*h*cos(theta(i))).^2)) == 0, h);
y(i) = double(F);
end
y
y = 1×7
0 0 0 0 0 0 0
  2 件のコメント
Chunru
Chunru 2022 年 5 月 5 日
To display the result for debugginh purpose

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2022 年 5 月 5 日
編集済み: John D'Errico 2022 年 5 月 5 日
A nonlinear problem like this is called an implicit function. You can think of the value of h, as a function of theta, but there will be no algebraic solution, so no simple way to write the functional relationship. And very often, there will be multiple such solutions. Here there will be infinitely many solutions. In these cases, it is best to use fimplicit to plot the relationship. I could do it using symboliic parameters, or just by using function handles.
Next, you need to understand that if your variable theta is defined between 30 and 90, then the units are certainly degreees, NOT radians. But sin and cos work in RADIANS. In order to use degrees, you use sind and cosd. But then you have a variable called period, and period is a small number. ANd then you put pi in there. So I think you may be confused about the distinction between radians and degrees.
Next, you do NOT put a space between the . and the * as that causes a syntax error. You really need to read the getting started tutorials!
F = (cos (theta). * (sin (k. h)). ^2) - (2. *(sin (k. *h. *cos (theta)). ^2))
Invalid use of operator
As well, there is no space between the . and the ^ operator too. You also seem to be adding extra spaces everywhere, even between the sin and the parens. Again, that can cause problems.
So to solve your problem, I would do this, without needing the symbolic toolbox. I could do it using symbolic tools too, by defining theta and h as symbolic variables.
period=0.562;
k = @(theta) (2.*pi)./(period.*sind(theta));
F = @(theta,h) (cosd(theta).*(sind(k(theta).*h)).^2) - (2.*(sind(k(theta).*h.*cosd(theta)).^2));
fimplicit(F,[30,90,0,90])
xlabel theta
ylabel h
grid on
The curved lines in blue are all solutions of the problem. As you can see there are many such solutions, and I had to guess what limits to plot for h.
Next I'll do it using syms:
syms theta h
period=0.562;
k = (2.*pi)./(period.*sind(theta));
F = (cosd(theta).*(sind(k.*h)).^2) - (2.*(sind(k.*h.*cosd(theta)).^2));
fimplicit(F,[0,90,30,90])
xlabel h
ylabel theta
grid on
As you can see, fimplicit puts h on the x axis, I assume because h comes before theta in alphabetical order. I could probably get fimplicit to swap the axes with some work.
  1 件のコメント
Rik
Rik 2022 年 5 月 5 日
Comment posted as flag by @RAVI:
you are right

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

Community Treasure Hunt

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

Start Hunting!

Translated by