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 make] a plot of x to the x

Subject: [how to make] a plot of x to the x

From: congruentialuminaire@yahoo.com

Date: 22 Feb, 2009 04:12:13

Message: 1 of 5

Hello UG:

I want to make a plot of this function.

I can differentiate it if I use:

syms x
y=x^x
diff(y,x)

but when I try to plot, I get:

plot(y,x)
??? Error using ==> plot
Conversion to double from sym is not possible.

I can also do this:

w=[0;0.1;5];
u=w^w

but Matlab says:

??? Error using ==> mpower
At least one operand must be scalar.

I can guess there is a simple way to do this, which is eluding me.

Thanks in advance.

Roger Williams
Franklin Laboratory

Subject: [how to make] a plot of x to the x

From: Roger Stafford

Date: 22 Feb, 2009 04:55:03

Message: 2 of 5

congruentialuminaire@yahoo.com wrote in message <c13f048a-c8ee-4888-8842-35d351bf44e8@t13g2000yqc.googlegroups.com>...
> Hello UG:
>
> I want to make a plot of this function.
>
> I can differentiate it if I use:
>
> syms x
> y=x^x
> diff(y,x)
>
> but when I try to plot, I get:
>
> plot(y,x)
> ??? Error using ==> plot
> Conversion to double from sym is not possible.
>
> I can also do this:
>
> w=[0;0.1;5];
> u=w^w
>
> but Matlab says:
>
> ??? Error using ==> mpower
> At least one operand must be scalar.
>
> I can guess there is a simple way to do this, which is eluding me.
>
> Thanks in advance.
>
> Roger Williams
> Franklin Laboratory

  If you write

 w=[0;0.1;5];
 u=w.^w;

it should work properly. When you wrote w^w it took the matrix power of a matrix which is not what you intended.

Roger Stafford

Subject: [how to make] a plot of x to the x

From: Steven Lord

Date: 23 Feb, 2009 15:45:22

Message: 3 of 5


<congruentialuminaire@yahoo.com> wrote in message
news:c13f048a-c8ee-4888-8842-35d351bf44e8@t13g2000yqc.googlegroups.com...
> Hello UG:
>
> I want to make a plot of this function.
>
> I can differentiate it if I use:
>
> syms x
> y=x^x
> diff(y,x)
>
> but when I try to plot, I get:
>
> plot(y,x)
> ??? Error using ==> plot
> Conversion to double from sym is not possible.

Yes. PLOT does not support sym objects; you'll need to evaluate the sym
object using SUBS and convert it to double precision using DOUBLE before you
can PLOT it. Alternately, you could use EZPLOT.

> I can also do this:
>
> w=[0;0.1;5];
> u=w^w
>
> but Matlab says:
>
> ??? Error using ==> mpower
> At least one operand must be scalar.

When you use w^w, you're trying to raise the matrix w to the wth power.
That doesn't make sense unless w is a scalar (what does it mean to raise [1
2] to the [1 2] power?)

What you want is to raise each element of w to the power of the
corresponding element of w. To do that, you need the elementwise POWER
operator (.^).

w = [0; 0.1; 5];
u = w.^w;

--
Steve Lord
slord@mathworks.com

Subject: [how to make] a plot of x to the x

From: Alan Weiss

Date: 23 Feb, 2009 16:01:54

Message: 4 of 5

I'm not sure what the problem is. I get a nice-looking plot with the
following commands:

syms x
y = x^x;
ezplot(y,[0,2])

Alan Weiss
MATLAB mathematical toolbox documentation

Roger Stafford wrote:
> congruentialuminaire@yahoo.com wrote in message <c13f048a-c8ee-4888-8842-35d351bf44e8@t13g2000yqc.googlegroups.com>...
>> Hello UG:
>>
>> I want to make a plot of this function.
>>
>> I can differentiate it if I use:
>>
>> syms x
>> y=x^x
>> diff(y,x)
>>
>> but when I try to plot, I get:
>>
>> plot(y,x)
>> ??? Error using ==> plot
>> Conversion to double from sym is not possible.
>>
>> I can also do this:
>>
>> w=[0;0.1;5];
>> u=w^w
>>
>> but Matlab says:
>>
>> ??? Error using ==> mpower
>> At least one operand must be scalar.
>>
>> I can guess there is a simple way to do this, which is eluding me.
>>
>> Thanks in advance.
>>
>> Roger Williams
>> Franklin Laboratory
>
> If you write
>
> w=[0;0.1;5];
> u=w.^w;
>
> it should work properly. When you wrote w^w it took the matrix power of a matrix which is not what you intended.
>
> Roger Stafford

Subject: [how to make] a plot of x to the x

From: Daniel Dycus

Date: 21 Nov, 2009 23:26:01

Message: 5 of 5

"Steven Lord" <slord@mathworks.com> wrote in message <gnugai$ra8$1@fred.mathworks.com>...
>
> <congruentialuminaire@yahoo.com> wrote in message
> news:c13f048a-c8ee-4888-8842-35d351bf44e8@t13g2000yqc.googlegroups.com...
> > Hello UG:
> >
> > I want to make a plot of this function.
> >
> > I can differentiate it if I use:
> >
> > syms x
> > y=x^x
> > diff(y,x)
> >
> > but when I try to plot, I get:
> >
> > plot(y,x)
> > ??? Error using ==> plot
> > Conversion to double from sym is not possible.
>
> Yes. PLOT does not support sym objects; you'll need to evaluate the sym
> object using SUBS and convert it to double precision using DOUBLE before you
> can PLOT it. Alternately, you could use EZPLOT.
>
> > I can also do this:
> >
> > w=[0;0.1;5];
> > u=w^w
> >
> > but Matlab says:
> >
> > ??? Error using ==> mpower
> > At least one operand must be scalar.
>
> When you use w^w, you're trying to raise the matrix w to the wth power.
> That doesn't make sense unless w is a scalar (what does it mean to raise [1
> 2] to the [1 2] power?)
>
> What you want is to raise each element of w to the power of the
> corresponding element of w. To do that, you need the elementwise POWER
> operator (.^).
>
> w = [0; 0.1; 5];
> u = w.^w;
>
> --
> Steve Lord
> slord@mathworks.com
>

This is exactly what I am looking for. However, lets say I have a string of numbers 1-200. How do I say u^(1:200) taking each value at a time without creating something like w=[1;2;3...200]

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