Answered

Solving a first order ODE with Euler backwards method

Your y_true is only valid for t>= 5 (smaller values give imaginary results for y). So, try going from 5 to 8: % y_true = log(t...

Solving a first order ODE with Euler backwards method

Your y_true is only valid for t>= 5 (smaller values give imaginary results for y). So, try going from 5 to 8: % y_true = log(t...

4 månader ago | 0

| accepted

Answered

Need help to create a loop

How about: e=2.7183; gamma=0.1333; k = [1,9,23,7,23,9,20,29,63,102,73,59,27,130,75,185,70,92,326]; Rt=0:0.01:10; P = zero...

Need help to create a loop

How about: e=2.7183; gamma=0.1333; k = [1,9,23,7,23,9,20,29,63,102,73,59,27,130,75,185,70,92,326]; Rt=0:0.01:10; P = zero...

4 månader ago | 1

Answered

Newton's method iterations

I suggest you plot a graph of your function, then you can see where good initial estimates would be. For example f = @(x) 2*ex...

Newton's method iterations

I suggest you plot a graph of your function, then you can see where good initial estimates would be. For example f = @(x) 2*ex...

4 månader ago | 0

Answered

the variable appears to change size every loop iteration

Answered here: https://uk.mathworks.com/matlabcentral/answers/1464024-the-variable-appears-to-change-size-every-loop-iteration?s...

the variable appears to change size every loop iteration

Answered here: https://uk.mathworks.com/matlabcentral/answers/1464024-the-variable-appears-to-change-size-every-loop-iteration?s...

4 månader ago | 1

Answered

Writing the dirac function as a function handle

Try dirac_i = @(x) x==i; % This assumes i has been fixed before the function is defined

Writing the dirac function as a function handle

Try dirac_i = @(x) x==i; % This assumes i has been fixed before the function is defined

4 månader ago | 0

| accepted

Answered

How to plot 2 graphs with input as a range and join them together?

Like this p0=0; p1=6; p2=1; p3=3; p4=3; t=[0:0.01:1]; x1 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p0)+(((3*(t.^3))-(6*(t....

How to plot 2 graphs with input as a range and join them together?

Like this p0=0; p1=6; p2=1; p3=3; p4=3; t=[0:0.01:1]; x1 = (1/6)*[((((-t).^3)+(3*(t.^2))-(3*t)+1)*p0)+(((3*(t.^3))-(6*(t....

4 månader ago | 0

Answered

the variable appears to change size every loop iteration

You don't need the loop: If = [0 0.5 1.0 1.5 2.0 2.5]; Ea = [0 75 150 205 242 270]; Ra = 0.14; RI = 2; la = 100; Ifield = ...

the variable appears to change size every loop iteration

You don't need the loop: If = [0 0.5 1.0 1.5 2.0 2.5]; Ea = [0 75 150 205 242 270]; Ra = 0.14; RI = 2; la = 100; Ifield = ...

4 månader ago | 1

Answered

Unable to find solution to matrix using Gauss Seidal code. How should I proceed to get the solution?

You are dividing by A(i,i) some of which are zero. These will introduce NaNs.

Unable to find solution to matrix using Gauss Seidal code. How should I proceed to get the solution?

You are dividing by A(i,i) some of which are zero. These will introduce NaNs.

4 månader ago | 0

Answered

Solving Eqn with Varying Variable (Ms)

Like this: a1a4 = 1./[1, 2, 4, 10]; n = 10000; p4p1 = 1:n; M = zeros(numel(a1a4),n); for j = 1:numel(a1a4) m = 1.01; ...

Solving Eqn with Varying Variable (Ms)

Like this: a1a4 = 1./[1, 2, 4, 10]; n = 10000; p4p1 = 1:n; M = zeros(numel(a1a4),n); for j = 1:numel(a1a4) m = 1.01; ...

4 månader ago | 1

| accepted

Answered

To solve two 2nd order coupled differential equation using ODE45?

Replace each 2nd order ODE by two 1st order ODEs. e.g. set V1 = X1', V2 = X2', then V1' = (50*sin(f(t) - V1)*V2')/sin(f(t)), V...

To solve two 2nd order coupled differential equation using ODE45?

Replace each 2nd order ODE by two 1st order ODEs. e.g. set V1 = X1', V2 = X2', then V1' = (50*sin(f(t) - V1)*V2')/sin(f(t)), V...

4 månader ago | 0

| accepted

Answered

Using Ode45 to solve dynamics problem (ISA model)

Like this z0 = 39045; %const.h0; v0 = 0; %const.v0; t0 = 0; tf = 800; N = 60000; tspan = linspace(t0, tf, N); X ...

Using Ode45 to solve dynamics problem (ISA model)

Like this z0 = 39045; %const.h0; v0 = 0; %const.v0; t0 = 0; tf = 800; N = 60000; tspan = linspace(t0, tf, N); X ...

4 månader ago | 0

| accepted

Answered

Curve fitting a power law function

Like this? h0=0.654; %[m] This seems to be unused h_t=[0.654;0.628;0.604;0.582;0.56;0.54;0.52;0.501;0.482;0.465;0.447;0.43;0.4...

Curve fitting a power law function

Like this? h0=0.654; %[m] This seems to be unused h_t=[0.654;0.628;0.604;0.582;0.56;0.54;0.52;0.501;0.482;0.465;0.447;0.43;0.4...

4 månader ago | 0

Answered

Finding approximate real solution to a equation

You don't need syms here. Try the roots function. help roots

Finding approximate real solution to a equation

You don't need syms here. Try the roots function. help roots

4 månader ago | 0

| accepted

Answered

Two Step Adam Bashford Method

As follows f=@(t,y) 3*t+y/t; alpha=5; a=1; b=2; n=3; [t, w, h] = abs2(f, a, b, alpha, n); plot(t,w,'-o'),grid xlabel('t'...

Two Step Adam Bashford Method

As follows f=@(t,y) 3*t+y/t; alpha=5; a=1; b=2; n=3; [t, w, h] = abs2(f, a, b, alpha, n); plot(t,w,'-o'),grid xlabel('t'...

4 månader ago | 0

| accepted

Answered

How to add iterations in Newton Raphson code of Kepler Equation

Like this M = 0.908; e = 0.725; tol = 10^-6; [E, its] = Kepler(M,e,tol); disp(['E = ' num2str(E) ' after ' num2str(its), ...

How to add iterations in Newton Raphson code of Kepler Equation

Like this M = 0.908; e = 0.725; tol = 10^-6; [E, its] = Kepler(M,e,tol); disp(['E = ' num2str(E) ' after ' num2str(its), ...

4 månader ago | 0

| accepted

Answered

Let x=[2 4 6 8 10] and y=[1 3 5 7 9]. Compute for the vector z whose elements are equal to z= (xy+ y/x)/[(x+y)]^((y-x)) + 10^(x⁄y)

You need z = (((x.*y)+(y./x))./((x+y).^(y-x)))+10.^(x./y) % another dot here ^

Let x=[2 4 6 8 10] and y=[1 3 5 7 9]. Compute for the vector z whose elements are equal to z= (xy+ y/x)/[(x+y)]^((y-x)) + 10^(x⁄y)

You need z = (((x.*y)+(y./x))./((x+y).^(y-x)))+10.^(x./y) % another dot here ^

4 månader ago | 0

| accepted

Answered

how to find the root of function?

Like this? n_h0 = 0.1; %initial guess n_h = fzero(@n_h_fun, n_h0); disp(n_h) function a=n_h_fun(n_h) alpha=0.74; ...

how to find the root of function?

Like this? n_h0 = 0.1; %initial guess n_h = fzero(@n_h_fun, n_h0); disp(n_h) function a=n_h_fun(n_h) alpha=0.74; ...

4 månader ago | 1

| accepted

Answered

Newton's method for 2 dimension vectors

LIke this? % Functions f = @(XY) [XY(1).^3 - 3*XY(1).*XY(2).^2 - 1; 3*XY(1).^2.*XY(2) - XY(2).^3]; J = @(XY) [...

Newton's method for 2 dimension vectors

LIke this? % Functions f = @(XY) [XY(1).^3 - 3*XY(1).*XY(2).^2 - 1; 3*XY(1).^2.*XY(2) - XY(2).^3]; J = @(XY) [...

4 månader ago | 0

Answered

How to plot a (which is changing from 0-1 in 0.01 increments) vs x(2) (using a for loop and fsolve to find the solution of a nonlinear equation containing x(s) sol based on a

Your first equation is a simple quadratic in x(1); your second is a quadratic in x(2) that depends on x(1), so, assuming you are...

How to plot a (which is changing from 0-1 in 0.01 increments) vs x(2) (using a for loop and fsolve to find the solution of a nonlinear equation containing x(s) sol based on a

Your first equation is a simple quadratic in x(1); your second is a quadratic in x(2) that depends on x(1), so, assuming you are...

4 månader ago | 0

Answered

to plot alpha(a) vs diameter(D) in the given problem. where A = l*sin(b), B = l*cos(b), C = ( h + 0.5*D )*sin(b) − 0.5*D*tan(b) and E = ( h + 0.5*D)*cos(b) − 0.5*D.

Try replacing D within the j-loop by D(j). Also add something like alpha(j) = a after the end of the i-loop (but inside the j-l...

to plot alpha(a) vs diameter(D) in the given problem. where A = l*sin(b), B = l*cos(b), C = ( h + 0.5*D )*sin(b) − 0.5*D*tan(b) and E = ( h + 0.5*D)*cos(b) − 0.5*D.

Try replacing D within the j-loop by D(j). Also add something like alpha(j) = a after the end of the i-loop (but inside the j-l...

4 månader ago | 0

Answered

Solving factorial equation with integer variables: Empty sym 0-by-1

Set x-2 = 659 and y-x = 679 for one solution, and x-2 = 679 and y-x = 659 for another.

Solving factorial equation with integer variables: Empty sym 0-by-1

Set x-2 = 659 and y-x = 679 for one solution, and x-2 = 679 and y-x = 659 for another.

4 månader ago | 0

Answered

Unable to plot exponential graphs properly

One possibility t = linspace(-10,10,400); y1 = exp(t); y2 = exp(-t); y3 = exp(2*t); plot(t,y1,t,y2,t,y3) legend('y1','y2...

Unable to plot exponential graphs properly

One possibility t = linspace(-10,10,400); y1 = exp(t); y2 = exp(-t); y3 = exp(2*t); plot(t,y1,t,y2,t,y3) legend('y1','y2...

4 månader ago | 0

Answered

Not enough input arguments.

Like this?: global PT S DELH Q CPA CPB CPC CPD NA NC NB ND NE NT PT = 1.5; % PT is total pressure in atmospheres S = 0.05; %...

Not enough input arguments.

Like this?: global PT S DELH Q CPA CPB CPC CPD NA NC NB ND NE NT PT = 1.5; % PT is total pressure in atmospheres S = 0.05; %...

4 månader ago | 1

| accepted

Answered

speed up integrating the same function over many overlapping intervals?

How about using cumtrapz to do the cumulative integral from 0 to max(X) just once, then select the sections specified by X(i).

speed up integrating the same function over many overlapping intervals?

How about using cumtrapz to do the cumulative integral from 0 to max(X) just once, then select the sections specified by X(i).

4 månader ago | 0

| accepted

Answered

Solving single variable equation where other variables depends on that single variable

Try using fzero. For example: f = @(x) x.^2 +1./x; % arbitrary function: replace with your own y = @(x) f(x); z = @(x)...

Solving single variable equation where other variables depends on that single variable

Try using fzero. For example: f = @(x) x.^2 +1./x; % arbitrary function: replace with your own y = @(x) f(x); z = @(x)...

4 månader ago | 0

| accepted

Answered

last value of array

Do you mean something like this %plot n vs x n vs y for n=1:10 [t,r]=ode45(@fn,[0 14],[0.01+n 0.01 ]); xlast(n) = r(end,1);...

last value of array

Do you mean something like this %plot n vs x n vs y for n=1:10 [t,r]=ode45(@fn,[0 14],[0.01+n 0.01 ]); xlast(n) = r(end,1);...

5 månader ago | 0

Answered

How to keep both readability and calculation speed when using anonymous functions?

How about something like hexp = @(x,y) exp(1i*(x+y)); x = ..; % set to whatever is required y = sqrt(x.^2 + A^2); h1 = h...

How to keep both readability and calculation speed when using anonymous functions?

How about something like hexp = @(x,y) exp(1i*(x+y)); x = ..; % set to whatever is required y = sqrt(x.^2 + A^2); h1 = h...

5 månader ago | 0

Answered

Non-linear system of inequalities

First plot some lines that bound the inequalities % G>21 % 15<=S<=18 % 61<=2S+G<=63 % 30<=atan(S/G)<=45 -> sqrt(3)/3 <= S/...

Non-linear system of inequalities

First plot some lines that bound the inequalities % G>21 % 15<=S<=18 % 61<=2S+G<=63 % 30<=atan(S/G)<=45 -> sqrt(3)/3 <= S/...

5 månader ago | 1

Answered

How to request a specific user input?

You don't need "input" twice: prompt = 'Please enter 1 for EXP1 and 2 for EXP2:'; % ask EXP = input(prompt); if ...

How to request a specific user input?

You don't need "input" twice: prompt = 'Please enter 1 for EXP1 and 2 for EXP2:'; % ask EXP = input(prompt); if ...

5 månader ago | 0