I need to find the angle from horizontal that tangents to a curve make for multiple points

26 ビュー (過去 30 日間)
Hi All,
I have [x,y] coordinates that form a convex shape, I need to find the tangent and subsequently the angle from horizontal that each tangent makes at each [x,y] coordinate.
I have used two different approaches so far but I have struggled with both. Firstly, I attempted to use polyfit to create an equation from the points, then polyder to find the derivative and finally polyval to find the gradients at each point. I got really small values for the gradient that don't make sense to me.
Secondly, I am attempting to use a system whereby I find the slope with s(i) = ( y(i+1)-y(i-1) ) / ( x(i+1) - x(i-1) ). Then I need to find the expression for the line. I am struggling with how to set up a for loop where I can select the +1 and -1 values of x and y within the same loop and how to create an equation for the line.
The 2nd image that I have attached explains exactly what I am trying to acheive.
Can anyone help me out?
global rmax deltar npi npj th gamma Ma T_inf V_inf cp_air rho_air R_air
rmax = rmax + deltar;
x = rmax.*cos(th);
y = rmax.*sin(th);
coord = [x, y];
p = polyfit(x,y,2);
d = polyder(p);
val = polyval(d, x);

採用された回答

Star Strider
Star Strider 2020 年 8 月 8 日
I am not certain what you want to do, or the result you want.
The easiest way to calculate numerical derivatives is to use the gradient function.
See if this approaches what you want to do:
rmax = 0.25;
th = linspace(pi/2, -pi/2, 25);
h = diff(th(1:2));
x = rmax.*cos(th);
y = rmax.*sin(th);
dx = gradient(x, h); % Numerical Derivative: dx
dy = gradient(y, h); % Numerical Derivative: dy
slope = dy ./ dx;
figure
plot(x, y, '+')
hold on
quiver(x, y, dx, dy, '-r') % Draw ‘quiver’ Arrows
hold off
axis('equal')
The advantage of using gradient rather than diff is that gradient is more accurate, and the output is the same size as the input.
  21 件のコメント
Laurence Maskell
Laurence Maskell 2020 年 8 月 24 日
Hi Star Strider,
Thank you for the advice, I am going to try an alternative method, I have made a change to the script but am now receiving the erorr below. I have looked at the forums but have been unable to resolve my problem. Perhaps another eye on it might spot something I haven't. I've attached my code as well.
I used a breakpoint on line 77 as the rest of the script still needs further work.
Kind Regards,
Laurence
Error using Ablation_analysis>Cpcalc
Too many input arguments.
Error in Ablation_analysis (line 69)
[Cp_max, Cp, T_0, p_inf, p_0_inf, p_0_1, p_e, p_w, Ma_e, T_e, T_0_e, V_e] = Cpcalc(gamma, Ma, slope, T_inf,
V_inf, cp_air, rho_air, R_air, T_inf);
Star Strider
Star Strider 2020 年 8 月 24 日
Without looking at anything else, the error is obvious: you are passing too many input arguments to ‘Cpcalc’. That is not something I can solve, since only you know what arguments should be passed to it and what arguments should not.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by