Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to define a constant in Matlab .... !!!??

Subject: How to define a constant in Matlab .... !!!??

From: Animesh Pandey

Date: 17 Apr, 2011 18:20:14

Message: 1 of 4

f = @(t) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t+0.5*a)));
This is a function that is same as a Pulse function....
ie. heaviside(t + 0.5*a) - heaviside(t - 0.5*a) !!

I wish to plot both of them as general functions with a constant 'a' .....
But when I do I get a plot of 'a vs t' .....
But I want 'a' be constant !!!!

a = 1;
f = @(t) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t+0.5*a)));
ezplot(f(t));
This gives a correct plot ..... but is this possible to show for any 'a' !!!!

Please help !!!
ASAP

Subject: How to define a constant in Matlab .... !!!??

From: ImageAnalyst

Date: 17 Apr, 2011 21:15:21

Message: 2 of 4

% Anonymous functions can have any number of arguments.
% The following anonymous function has two input arguments t and a:
f = @(t,a) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t
+0.5*a)));

Subject: How to define a constant in Matlab .... !!!??

From: Animesh Pandey

Date: 18 Apr, 2011 09:44:05

Message: 3 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <10c8c987-c70b-43a5-8425-2f288956cb08@m23g2000prl.googlegroups.com>...
> % Anonymous functions can have any number of arguments.
> % The following anonymous function has two input arguments t and a:
> f = @(t,a) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t
> +0.5*a)));


clc
syms t w a
I = sqrt(-1);
f = @(t,a) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t+0.5*a)));
f1= @(t,a) heaviside(t+0.5*a) - heaviside(t-0.5*a);
pretty(f(t,a));
ezplot(f(t,a));
figure, ezplot(f1(t,a));
H = int(f(t,a).*exp(-I*w*t), t, -Inf, Inf);
pretty(H);

Still I am getting NaN for pretty(H)......
It is supposed to be
   2sin(1/2 w a)/w .....
because
ezplot(f(t,a)) = ezplot(f1(t,a)) ...
                                

Subject: How to define a constant in Matlab .... !!!??

From: Steven_Lord

Date: 18 Apr, 2011 14:51:17

Message: 4 of 4



"Animesh Pandey" <apanimesh061@gmail.com> wrote in message
news:ioh155$kik$1@fred.mathworks.com...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <10c8c987-c70b-43a5-8425-2f288956cb08@m23g2000prl.googlegroups.com>...
>> % Anonymous functions can have any number of arguments.
>> % The following anonymous function has two input arguments t and a:
>> f = @(t,a) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t
>> +0.5*a)));
>
>
> clc
> syms t w a

While it is possible to mix symbolic expressions and anonymous functions,
there's no need to do so for your situation.

> I = sqrt(-1);
> f = @(t,a) 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t+0.5*a)));

syms t w a
f = 0.5*(((t+0.5*a)./abs(t+0.5*a)) - ((t-0.5*a)./abs(-t+0.5*a)));
f1 = heaviside(t+0.5*a) - heaviside(t-0.5*a);
ezplot(subs(f, a, 1))
axis([-1 2 -1 2])

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us