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:
Simple Matlab problem novice.

Subject: Simple Matlab problem novice.

From: theconster@gmail.com

Date: 21 Apr, 2009 01:45:49

Message: 1 of 3

Hi,

I have a simple problem, I am trying to plot the following function:

f(x) = ((x^4)*(1-x)^4)/(1-x^2)

on the interval [0,1].

I know that to do this on Matlab I need to set up the interval, and I
also know that i need to write my powers as x.^4; I wrote the
following code which I thought would work:


>> x = 0:0.5:4;
>> y = ((x.^4)*(1-x).^4)/(1-x.^2)

and got the following message:
??? Error using ==> mtimes
Inner matrix dimensions must agree.

I was wondering if anyone could tell me what I had done wrong, or if
they could show me how to do this plot.

Thanks in advance,
Tom

Subject: Simple Matlab problem novice.

From: Ambarish Jash

Date: 21 Apr, 2009 01:59:03

Message: 2 of 3

This is what u have written y = ((x.^4)*(1-x).^4)/(1-x.^2)
This is what you need to do y = ((x.^4).*(1-x).^4)./(1-x.^2)
Notice the 2 extra dots (one before the * and the other before the /)
theconster@gmail.com wrote in message <2ab28b31-3dbd-4943-9638-bdc1d7be5c0d@x5g2000yqk.googlegroups.com>...
> Hi,
>
> I have a simple problem, I am trying to plot the following function:
>
> f(x) = ((x^4)*(1-x)^4)/(1-x^2)
>
> on the interval [0,1].
>
> I know that to do this on Matlab I need to set up the interval, and I
> also know that i need to write my powers as x.^4; I wrote the
> following code which I thought would work:
>
>
> >> x = 0:0.5:4;
> >> y = ((x.^4)*(1-x).^4)/(1-x.^2)
>
> and got the following message:
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> I was wondering if anyone could tell me what I had done wrong, or if
> they could show me how to do this plot.
>
> Thanks in advance,
> Tom

Subject: Simple Matlab problem novice.

From: Roger Stafford

Date: 21 Apr, 2009 02:13:01

Message: 3 of 3

"Ambarish Jash" <ambarish.jash@colorado.edu> wrote in message <gsj997$spm$1@fred.mathworks.com>...
> This is what u have written y = ((x.^4)*(1-x).^4)/(1-x.^2)
> This is what you need to do y = ((x.^4).*(1-x).^4)./(1-x.^2)

> > >> x = 0:0.5:4;
> > >> y = ((x.^4)*(1-x).^4)/(1-x.^2)

  When you have corrected to ".*" and "./", you are still headed for trouble at the value x = 1. You have a zero-divided-by-zero situation there which will produce a NaN. You should first cancel out a factor of 1-x in the numerator with the same factor in the denominator before generating y.

Roger Stafford

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