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

26 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Star Strider
Star Strider el 8 de Ag. de 2020
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 comentarios
Laurence Maskell
Laurence Maskell el 24 de Ag. de 2020
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 el 24 de Ag. de 2020
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by