Integral problem cant get it to give me a number

I got an assigment where i have to plot two functions and thereafter use a formula where we integrate the differentiate of the two functions to find the length of the figure, but i cant get it to work, hope you can help me out:
clear, clc
close all, close all hidden
t=linspace(0,2*pi,100);
b=5
X=2*b*cos(t)-b*cos(2*t);
Y=2*b*sin(t)-b*sin(2*t);
plot(X,Y)
clear, clc
syms b, syms t
X=2*b*cos(t)-b*cos(2*t);
Y=2*b*sin(t)-b*sin(2*t);
X1=diff(X);
Y1=diff(Y);
F= @ (x) sqrt((X1).^2+(Y1).^2);
b=5;
L=quadl(F,0,2*pi)

1 Comment

What are you intending to differentiate with respect to? You have two variables in the expression. The Symbolic Toolkit does have rules about which variable has priority, but the rules are not easy to remember and other people reading the code are not likely to know them, so you should be specific about the variable of differentiation in the diff() call.

Sign in to comment.

Answers (1)

You should look at the documentation for int, the integration function specific to the Symbolic Toolbox. You will also need subs, which is how you substitute in numeric values for your symbolic variables.
Only your last three lines need to change.
F = sqrt((X1).^2+(Y1).^2);
F = subs(F,b,5);
L = int(F,t,0,2*pi)

Categories

Asked:

on 10 Mar 2016

Commented:

on 10 Mar 2016

Community Treasure Hunt

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

Start Hunting!