Left-rotating a vector
You define B as a null vector so it doesn't have an "end". Try, simply A = [1,2,3,4,5]; B = [A(2:end) A(1)]

4 months ago | 0

| accepted

How can I solve this error : Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
This works for me: n=input('donner le nombre de points: '); k=0; for i=1:n u1=rand;u2=rand; x=2*u1; y=2*u2...

4 months ago | 0

Lax-Wendroff method for advection equation with periodic boundary condition
If you make dt=0.1*h/a; instead of dt=0.95*h/a; your max error reduces to 0.0355.

4 months ago | 0

I want to solve the unknown variable t1
Well, this gets it working, though who knows if it makes any sense!" A0 =500; D0=100; c1=5; c2=10; c3=10; c4=8; a=30; a2...

4 months ago | 0

How to make convergence plot (error VS time step) in a log-log scale among four numerical methods and exact solution?
This should give you the right idea: %% 1st-order Adams-Bashforh Solution fun = @(t,y) (y); %Function f(t,y) y0 = 1; %Initial...

4 months ago | 0

i need some help with finding the damping ratio
Use fzero: x = [12.73, 25.36, 37.99]; y = [0.77, 0.29, 0.11]/2; zeta = fzero(@(zeta) fn(zeta,y),0.5); disp(['zeta = ' nu...

4 months ago | 0

How to make graph that plot between Analytical Solution (Exact Solution) and Numerical Method Solution?
After Y = exactY(t2) you probably need something like: plot(t2,Y2,t2,Y) legend('AM','Exact') However, you haven't supplied th...

4 months ago | 0

| accepted

How to numerically solve and plot definite integral with variable upper limit
Like so: K= @(t) (sin(t)-t.*cos(t)).*sin(t); P = 0:0.1:3.1416; for i = 1:numel(P) V(i) = integral(K,0,P(i)); ...

4 months ago | 0

| accepted

merge two matrices after odd rows
Here's one way: A=[1 1;1 1;1 1]; B=[2 3;4 5;6 7]; AB = [A B]'; C = reshape(AB,2,6)'

4 months ago | 0

Hello, I am trying to solve the ODE but I have an error I do not understand how to solve. Would appreciate some help. Thank you!
Like this? %% ODE45_estimation % ------ Constants ------ % m = 1248.5; g = 9.81; W = m*g; S = 17.1; % ------ Time int...

4 months ago | 0

plotting Solid of revolution of a function
How about: X = 0:0.1:pi; R = sin(X); [z,x,y] = cylinder(R); surf(x,y,z)

4 months ago | 1

Split an array using specific points
Like this? Y = [5;2;3;6;7;9;5;5;6;3;8;7;74;9;63;47;10;3]; diiv = [5; 9; 15]; y1 = Y(1:diiv(1)); y2 = Y(diiv(1)+1:diiv(2)); ...

4 months ago | 1

Algorithm for Fractional power calculation
How about using the Newton-Raphson algorithm. Here's the basic idea: % x^n = b % Let f(x) = x^n - b % dfdx(x) = n*x^(n-1) %...

4 months ago | 0

Stochastic differential equation Gompertz plotting a graph
You have x(1) = 0, so log(x(1)) is -Inf, which means that subsequent values of x will be NaNs.

4 months ago | 0

| accepted

Defining integration function in matlanb
Like this? % If Cp is a constant then the integral is just Cp*T % If it is a function of T, then define the function: Cp = @(...

4 months ago | 0

Plotting and coding problems
More like this perhaps: T = 300:0.5:500; w = 0.224; Tc = 304.2; ...

4 months ago | 0

You need multiplication signs between n and (w1+k) in calculations of u and z: [X,Y] = meshgrid(-4:0.2:4); n=2; k=1; %n=1,...

4 months ago | 0

Need help in finding all the solutions of non linear ellipse equations using Newtons Method using following code.
Check your Jacobian equations, especially the term: 2*x(1)+2*x(1)+4; I think this should be 2*x(1)+2*x(2)+4;

4 months ago | 1

Displayin command just once for the n number of iterations
What about if k == 0 disp("Hello World!") elseif k == 480 disp("Bye Bye World!") end

5 months ago | 0

Index in position 1 is invalid. Array indices must be positive integers or logical values.
In line V(i,j+1) = ((1-2*s-k).*V (i,j))+ (s.*(V (i-1,j) + V (i+1,j))) - (k.*(Rm.*Iinj+Vrest)); you have V (i-1,j). When i is ...

5 months ago | 0

| accepted

What is the way of solving the noise added differential equations in matlab?
Try to avoid the (mis)use of global! %% ----------------INPUT PARAMETERS--------------------------- f=0.33; alpha=0.5; w0=sqrt...

5 months ago | 0

| accepted

Unable to perform assignment because the left and right sides have a different number of elements.
Like this? clear %Vmax values for each reaction step v1=0.01:0.01:2; v2=1; %Km values for each reaction step K1=1; K2=1; ...

5 months ago | 0

| accepted

How do I create a stacked plot like attached figure using subplot command ?
Try help stackedplot

5 months ago | 0

| accepted

More like this: % Write equations as follows: % dudx = v u(0)=-1 % dvdx = -v/4-6u v(0)=0 % % Then you hav...

5 months ago | 1

| accepted

Runge Kutta 3 ODE
You can't have t(i)=t(0)+i*h; indices must be a positive integer - you have t(0), Matlab doesn't like this!

5 months ago | 0

| accepted

Why it is saying this? Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in Homework (line 21) surf(x,y,F(i,j))
Like this x=[-5:5]; y=[-5:5]; for i=1:numel(x) for j=1:numel(y) if (x(i)>=0)&&(y(j)>=0) F(i,j)=2.*x(i)+y(j)^2; en...

5 months ago | 0

| accepted

Definite integral with parameter
You could try something like this: a = 0.043478; q = 100; % Ha W = 40; t = 4; c = @(x,Fa )(5.*x.^2-Fa.*x)./(((a.*x+q).*W-((...

5 months ago | 0

| accepted

Integration of a joint pdf with for loop?
When k = 1and i = 1 then k-i = 0, therefore the second index in fun(i,k-i) is 0, but indices must be positive integers in Matlab...

5 months ago | 0