Maple can't solve sample code - maple

I couldn't get Maple to solve this sample function at its own documentation:
rsolve({y(n)=ny(n−1),y(0)=1},y)
The output in the documentation is Gamma(n+1). But when I executed the code, Maple only returns
{y(0) = 1, y(n) = ny(n-1)}
Any help is much appreciated!

You forgot to put multiplication there. Now ny is seen as a variable, and not as n*y. If you insert the mulitplication or a space, then the output is indeed Gamma(n+1)

Related

matlab 3 equations result problems

I am not good at matlab but I have to write short programs for my exams, so I started to prepare.
3 equations So these must be solved with f solve and I have to display the result of these, but this time I have to start from the origo.
My code is:
x = fsolve(y,x)
function y = t(x)
y=zeros(3,1);
x=ones(3,1);
y(1)=x(1).^3-11*x(1)+x(2).^2+9;
y(2)=x(1)*x(2).^2+x(2)-10*x(1)-11*x(3);
y(3)=x(1)*x(2)+x(3).^4-10*x(2)+8;
end
So as I think my refering of the function is bad. I hope it is and no more mistake in it. The error is: https://imgur.com/a/Slbi1tV
Could you help me out?
Thanking you in advance and have a good health all of you!

how to convert this result using exponentials to hyperbolic trig functions?

The solution to Laplace PDE on rectangle is usually written using hyperbolic trig functions. I solve this PDE using Maple. Verified Maple solution is correct. But having hard time figuring how to make its result match the book result.
I tried sol:=convert(rhs(sol),trigh): then simplify(sol,trig); and it become little closer to the book solution, but is still can be more simplified.
Are there any tricks to do this?
Here is MWE
restart;
interface(showassumed=0):
pde:=diff(u(x,y),x$2)+diff(u(x,y),y$2)=0:
bc:=u(0,y)=0,u(a,y)=f(y),u(x,0)=0,u(x,b)=0:
sol:=pdsolve([pde,bc],u(x,y)) assuming(0<=x and x<=a and 0<=y and y<=b):
sol:=subs(infinity=20,sol);
Which gives
The above is same as the following, which I am trying to convert the above to
textbookU:= Sum(2*sin(n*Pi*y/b)*(Int(sin(n*Pi*y/b)*f(y),
y = 0 .. b))*sinh(n*Pi*x/b)/(b*sinh(n*Pi*a/b)), n = 1 .. 20);
The above are the same. I checked few points, and they give same answer. They must be the same, as the above textbook solution is correct, and I am assuming Maple solution is correct.
Now I tried to convert Maple sol to the above as follows
sol:=convert(rhs(sol),trigh):
simplify(sol,trig);
May be someone knows a better way to obtain the textbook solution form, starting from the Maple solution above.
Using Maple 2017.3 on windows
After the convert you can first expand it, to then simplify it again:
s := convert(sol, trigh):
s := expand(s):
simplify(s);
which gives:

How to use dsolve to return a real answer in Matlab

I tried this:
clear all
syms t real
assumeAlso(-1<t & t<1)
syms u(t)
sol2=dsolve(diff(u,t)==(2*t+sec(t)^2)/(2*u),u(0)==-5,t)
But it returns a complex answer.
Anyone have a way that this will return an answer with any i's in it?
You need to specify one more initial condition in your dsolve function, otherwise you will always see the t variable in the solution. Once this is done, all you have to do is to add the following piece of code:
vpa(subs(sol2),2)
at the bottom of your current script.

Integrate a function in Matlab

I know this is a novice question, but I'm new at Matlab and am trying to integrate a function for n=0, n=1, etc.. This is my code so far:
function x = t^n*(t+5)^-1
int(x,t=0..1)
And I keep on getting this error:
Error: File: a02_IX.m Line: 1 Column: 15
Unexpected MATLAB operator.
Does anyone know what this could be?
Thank you!
Try writing it this way:
function x = t^n/(t+5) int(x,t=0..1)
I think raising the term in parentheses to the -1 power reads badly. Maybe MATLAB is confused, too.
What's the value for n? Don't you need to specify that?
It helps to know the answer before you start. This is easy to integrate analytically.
The function looks like this for n=2:
http://www.wolframalpha.com/input/?i=plot+t%5E2%2F%28t%2B5%29+t%3D0..1
Here's the integral, both indefinite and definite:
http://www.wolframalpha.com/input/?i=integrate+t%5E2%2F%28t%2B5%29+from+t%3D0+to+1

MATLAB: not calculating correctly...user error?

I have been looking at this code for a while now, and cannot figure out why matlab is not calculating correctly. Does anyone see anything that I may be doing wrong with this code?
((1-EU_P2par3(:,1))*US_P2par3(:,1))+((1-EU_P2par3(:,2))*US_P2par3(:,2))+((1-EU_P2par3(:,3))*US_P2par3(:,3))+((1-EU_P2par3(:,4))*US_P2par3(:,4))+((1-EU_P2par3(:,5))*US_P2par3(:,5))+((1-EU_P2par3(:,6)*US_P2par3(:,6)))+((1-EU_P2par3(:,7))*US_P2par3(:,7))
Thanks for all the help!
In cases like this, good code formatting is your friend. Using an ellipsis (i.e. ..., the line continuation symbol) to create a multi-line statement can help greatly...
It looks like you have a parenthesis in the wrong place. Your code looks like this:
result = ((1-EU_P2par3(:,1))*US_P2par3(:,1))+...
((1-EU_P2par3(:,2))*US_P2par3(:,2))+...
((1-EU_P2par3(:,3))*US_P2par3(:,3))+...
((1-EU_P2par3(:,4))*US_P2par3(:,4))+...
((1-EU_P2par3(:,5))*US_P2par3(:,5))+...
((1-EU_P2par3(:,6)*US_P2par3(:,6)))+... %# Notice something here?
((1-EU_P2par3(:,7))*US_P2par3(:,7));
And you probably want this:
result = ((1-EU_P2par3(:,1))*US_P2par3(:,1))+...
((1-EU_P2par3(:,2))*US_P2par3(:,2))+...
((1-EU_P2par3(:,3))*US_P2par3(:,3))+...
((1-EU_P2par3(:,4))*US_P2par3(:,4))+...
((1-EU_P2par3(:,5))*US_P2par3(:,5))+...
((1-EU_P2par3(:,6))*US_P2par3(:,6))+... %# Notice the change?
((1-EU_P2par3(:,7))*US_P2par3(:,7));
EDIT:
In addition, as Darren mentions in his answer, you will likely have to use the element-wise multiplication operator .* instead of the matrix multiplication operator *. Explanations of the arithmetic operators can be found here.
Also, your calculation can be greatly simplified by vectorizing it using the function SUM, like so:
result = sum((1-EU_P2par3(:,1:7)).*US_P2par3(:,1:7),2);
Try the following example.
xy = rand(10,2);
a = xy(:,1)*xy(:,2);
% ??? Error using ==> mtimes
% Inner matrix dimensions must agree.
a = xy(:,1).*xy(:,2);
The error arises when you attempt to multiply vectors together. You must use the .* operator to get element-wise multiplication
Hope that helps