Using parametric equations in terms of theta1 and theta2 to plot a point A for a range of angles

8 ビュー (過去 30 日間)
I am trying to write a code that uses two parametric equations of x and y, which depend on the variables theta1 and theta2. Then I have to produce a plot of x Vs y for a range of values of theta1 and theta2. I am stuck how can I do this?
Bellow is my current code to display the coordinate of this point defined by the parametric equations a and b (btw this code doesn't work for reasons that I do not understand). Now I have to use these functions to produce an array that will plot the x,y coordinates over a range of values of theta1 (20 to 80 deg in increments of 0,5) and of theta2 (90 to 30 deg in increments if 0,5).
Thanks in advance for any help! Started Matlab a few weeks ago :) (I attached a screenshot of the question)
n1 = input('Enter θ1: ');
n2 = input('Enter θ2: ');
function a = first_calc(n1,n2)
a = 0.6*cosd(n1) + 0.2*cosd(n1-n2);
end
function b = second_calc(n1,n2)
b = 0.6*sind(n1) + 0.2*sind(n1-n2);
end
fprintf('The value for x is %g, and that of y is g%\n' a,b);

採用された回答

Krishna Zanwar
Krishna Zanwar 2019 年 2 月 26 日
Hey Raphael,
In this case you have defined a function but not called it in your script and so you are getting an error while printing the a and b variables.
You can just call the function in your script as
a = first_calc(n1,n2);
b = second_calc(n1,n2);
You can get the example on it here.
Secondly to create an array –
Theta1=20:0.5:80;
Theta2=90:-0.5:30;
You can learn how to use the plot function here.
  6 件のコメント
Krishna Zanwar
Krishna Zanwar 2019 年 3 月 1 日
I meant just put this in the script .
theta1=20:0.5:80;
theta2=90:-0.5:30;
a = 0.6*cosd(theta1) + 0.2*cosd(theta1-theta2);
b = 0.6*sind(theta1) + 0.2*sind(theta1-theta2);
plot(a,b)
xlabel('x Coordinate of Point A');
ylabel('Y Coordinate of Point A');
It will give you the same response.
Raphael Aubry
Raphael Aubry 2019 年 3 月 1 日
Hey thanks a lot Krishna! it works very well now - things need to be kept very simply it seems and then it works. Bellow is a photo of the code and graph

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

その他の回答 (1 件)

Krishna Zanwar
Krishna Zanwar 2019 年 2 月 27 日
Hey Raphael,
Since Matlab does direct calculations of Vectors you dont need a for loop for this problem.
theta1=20:0.5:80;
theta2=90:-0.5:30;
a = 0.6*cosd(theta1) + 0.2*cosd(theta1-theta2)
b = 0.6*sind(theta1) + 0.2*sind(theta1-theta2)
Hope it helps.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by