Help with fsolve command, in solving system of equations acquired by spectral collocation.

Hi,
I am solving a coupled system of equations using spectral collocation scheme,
u''+a1*t=a2;
t''=0;
with b.c
u=0,t=0.5 at y=0;
u=0,t=1 at y=1;
The set of equations at (N+1) collocation points will be described as:
D2*U+a1*T=a2;
D2*T=0;
with
U_0 = 0, T_0=1
U_N = 0, T_N=0.5
where
D2 is the differentiation matrix of order(N+1), given by D2=D*D
U and T are the vectors of unknowns
a1=30;
a2=-12;
with given boundary conditions, how can solve the set of algebraic equations in MATLAB?
Can it be solved using "fsolve"?
As I do now know how to express the vectores U and T in the code.

2 Commenti

Hi...Im priya...also doing Spectral collocation technique in my research...i have some doubts...can you please help me how to give an input in MATLAB.
my mail id :priya.jeni28@gmail.com
@Tanya Sharma Hi... Im Ehab, i run your program Tanya and solve the set of algebraic equations in MATLAB? using "solve (F)" we get the solution for N=3 only but no solution for N>3 why???? My email ehab_math@yahoo.com

Accedi per commentare.

 Risposta accettata

You are mixing notations it looks like to me. D*U would be used more for working with Laplace transforms. In the space you are working in, which is not the laplace space, you do not use multiplication notation and you cannot treat D like a variable to be solved for, and cannot use fsolve.
I would suggest that you use the symbolic toolbox and dsolve().

8 Commenti

Here D is a matrix,
for example for N=2,
D is a matrix of order 3by3:
D = [1.5 -2 0.5;
0.5 0 -0.5;
-0.5 2 -1.5];
D2=D*D=[1 -2 1;
1 -2 1;
1 -2 1];
a1=30;
a2=-12;
syms u(y) t(y)
Du = diff(u,y);
D2u = diff(Du,y);
Dt = diff(t,y);
D2t = diff(Dt,y);
eq1 = D2u + a1 * t == a2;
eq2 = D2t == 0;
sol_general = dsolve([eq1, eq2])
sol_general = struct with fields:
t: [1×1 sym] u: [1×1 sym]
sol_general.t
ans = 
simplify(sol_general.u)
ans = 
ic = [u(0) == 0, t(0) == 1/2, u(1) == 0, t(1) == 1]
ic = 
sol = dsolve([eq1, eq2, ic])
sol = struct with fields:
t: [1×1 sym] u: [1×1 sym]
sol.t
ans = 
simplify(sol.u)
ans = 
Those are the equations you specified. D is not a differentiation matrix, or at least not one that has anything to do with the equations you specified.
Those D matrices you show look like they might possibly be gradients for a system of PDE with three variables. However, the notation u'' would not be used for PDE.
Thanks for the insight into the symbolic solution of the problem Walter. How Can I plot the result obtained(t,u) with y in the code? and can I obtain u'' and t' of the solution at y=0?
I am however looking to solve the equations using numerical scheme(in section3.1) as described in the paper attached herewith by Motsa (motsa2011 QLSM.pdf)
where equations (15)–(18) form a system of nonlinear algebraic equations that are solved using the MATLAB nonlinear equation solver, fsolve.
The reference to the differentiation matrix is given by
Spectral Methods in Matlab, Lloyd N. Trefethen:
% CHEB compute D = differentiation matrix, x = Chebyshev grid
function [D,x] = cheb(N)
if N==0, D=0; x=1; return, end
x = cos(pi*(0:N)/N)';
c = [2; ones(N-1,1); 2].*(-1).^(0:N)';
X = repmat(x,1,N+1);
dX = X-X';
D = (c*(1./c)')./(dX+(eye(N+1))); % off-diagonal entries
D = D - diag(sum(D')); % diagonal entries
Hope this refernce makes the notationa used by me more clear.
thanks in advance.
fplot(sol.t, [0 UpperBoundTime])
fplot(sol.u, [0 UpperBoundTime])
subs(subs(D2u, sol), y, 0) %u''(0)
subs(subs(Dt, sol), y, 0) %y'(0)
I am not familiar with those methods.
A link for myself for future reference: https://people.maths.ox.ac.uk/trefethen/8all.pdf
Thanks Walter.
Let me put in this way:
The set of equations after using the method reduces to:
D2*U + a1*T=a2; %%system
D2*T=0;
In the code, the matrix D2 will be generated by calling the cheb function:
N=2;
[D,x]=cheb(N);
D2=D*D; %second derivative %1
This will give me the differntiation matrix. For instance: for N=2
D2=[1 -2 1; 1 -2 1; 1 -2 1];
Now I want a vector column for U and T, which will be of the length N+1 and should look like this:
U=[u(0); u(1); ... ;u(N)]; %2
T = [u(N+1); u(N+2);....;U(2N+2)]; %3
Using %1, %2 and %3 in system, will generate (2N+2) equations in (2N+2) unknowns. Which can be solved using the fsolve command.
But I am unable to generate the vector columns U and T of dimension (N+1)*1.
Thanks. I am able to create the system of equations (tanya1.m).
I applied to boundary condition as well.
Now how to solve them using fsolve?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by