Plot function with changing variable
Afficher commentaires plus anciens
So I have a function that approximately calculates the length of the space curve 2*sin(s),3*cos(s)*exp(s),s.^2/10.
function leng_straight = spacecurvelength(curve,a,b,n)
% Generating n x-points from a to b
syms s
xi= a:(b-a)/n:b;
yi=subs(curve,s,xi);% generating the y-values of the function
% assuming that between consecutive data points, the
% curve can be approximated by linear splines.
leng_straight=0;
m=length(xi);
% there are m-1 splines for m points
for i=1:1:m-1
dx=xi(i+1)-xi(i);
dy= yi(i+1)-yi(i);
leneach=sqrt(dx^2+dy^2);
leng_straight=leng_straight+leneach;
end
end
So I'm now trying to plot this function as I change the 'n' value which is the number of subintervals. Right now I'm getting a blank plot when I call it like this: I've tried changing the names of each of the 'length's to make it unique but no difference.
length = spacecurvelength(@(s) [2*sin(s),3*cos(s)*exp(s),s.^2/10],-4*pi,4*pi,2);
length = spacecurvelength(@(s) [2*sin(s),3*cos(s)*exp(s),s.^2/10],-4*pi,4*pi,5);
length = spacecurvelength(@(s) [2*sin(s),3*cos(s)*exp(s),s.^2/10],-4*pi,4*pi,10);
length = spacecurvelength(@(s) [2*sin(s),3*cos(s)*exp(s),s.^2/10],-4*pi,4*pi,20);
x=[2, 5, 10, 20];
y=length;
plot(x,y)
xlabel('n')
ylabel('length')
title(['Length of Space Curve as a function of n'])
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spline Postprocessing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!