Matlab function with array input problem

380 Views Asked by At

My question is simple but I just don't understand. I just wanted to plot Scorer function which is $$Hi(x)=\int_0^\infty{\exp(xt-\frac{t^3}{3})}dt.$$

First I tried to write, for example, x=0:0.1:1. Then I write

y = 1/(pi)*integral(@(s) exp(x*s -(s^3)/3),0,inf).

It shows error using * and inner matrix dimensions must agree.

I also tried .* and .^ but the error then becomes only, matrix dimensions must agree.

I know my question seems stupid but I am just starting to learn matlab. What is the problem and what should be the correct steps of plotting this function? Thank you!

1

There are 1 best solutions below

1
On

You need to loop through the different x inputs.For instance, the following will do what you are looking for:

$\texttt{x=0:0.1:1;}$

$\texttt{y=zeros(size(x));}$

$\texttt{for k=1:length(x)}$

$\quad \texttt{y(k)=1/pi*integral(@(s) exp(x(k)*s-s.^3/3),0,Inf);}$

$\texttt{end}$