Plot the graph using non linear equation

9 views (last 30 days)
Sun Heat
Sun Heat on 5 May 2022
Commented: Rik on 5 May 2022
Hey guys...
I have to plot the graph between "theta Vs h" value?
theta=linspace (30,90,7);
F=solve ((cos (theta). * (sin (k. h)). ^2) - (2. *(sin (k. *h. *cos (theta)). ^2)) == 0);
Thanks in advance
  1 Comment
Sun Heat
Sun Heat on 5 May 2022
i want to plot 'h' for different value of theta

Sign in to comment.

Accepted Answer

Chunru on 5 May 2022
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);
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);
y = 1×7
0 0 0 0 0 0 0
Chunru on 5 May 2022
To display the result for debugginh purpose

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 5 May 2022
Edited: John D'Errico on 5 May 2022
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.
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));
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
k = (2.*pi)./(period.*sind(theta));
F = (cosd(theta).*(sind(k.*h)).^2) - (2.*(sind(k.*h.*cosd(theta)).^2));
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 Comment
Rik on 5 May 2022
Comment posted as flag by @RAVI:
you are right

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by