Plot the graph using non linear equation

조회 수: 6 (최근 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
Sun Heat
Sun Heat 2022년 5월 5일
Thanks for replying,
Plz tell me why you write 'y' at last line...it is typo.
please also explain this line y(i) = double(F);
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by