Answered

Can I save a MATLAB variable generated by a function into another MATLAB function?

You can use global variables by this line of code in all functions that share the same variables: global var1 var2 var3

Can I save a MATLAB variable generated by a function into another MATLAB function?

You can use global variables by this line of code in all functions that share the same variables: global var1 var2 var3

2 years ago | 0

Answered

Factorial without the Command

Using only basic operations: function f = Factorial(n) % % initial value, 0! and 1! f = 1; if n > 1 for i=2:n ...

Factorial without the Command

Using only basic operations: function f = Factorial(n) % % initial value, 0! and 1! f = 1; if n > 1 for i=2:n ...

2 years ago | 0

Answered

Factorial without the Command

function f = Factorial(n) % % if n = 0 || n = 1 f = 1; elseif n >= 1 f = n * Factorial(n-1); end

Factorial without the Command

function f = Factorial(n) % % if n = 0 || n = 1 f = 1; elseif n >= 1 f = n * Factorial(n-1); end

2 years ago | 0

Answered

Loop for creating Submatrix

It should not be two nested loops. You can use one loop that increases a counter. You can use this code that doesn't need a loo...

Loop for creating Submatrix

It should not be two nested loops. You can use one loop that increases a counter. You can use this code that doesn't need a loo...

2 years ago | 0

| accepted

Answered

How to enter a function into matlab

H/2*sigma.*cosh(k.*(h+z))./sinh(k.*h).*cos(k.*x-sigma.*t) H/2*sigma.^2.*cosh(k.*(h+z))./sinh(k.*h).*sin(k.*x-sigma.*t)

How to enter a function into matlab

H/2*sigma.*cosh(k.*(h+z))./sinh(k.*h).*cos(k.*x-sigma.*t) H/2*sigma.^2.*cosh(k.*(h+z))./sinh(k.*h).*sin(k.*x-sigma.*t)

2 years ago | 0

| accepted

Answered

Index in position 1 exceeds array bounds (must not exceed 2 )

try this for i = j:size(A,1)

Index in position 1 exceeds array bounds (must not exceed 2 )

try this for i = j:size(A,1)

2 years ago | 0

Answered

Shadow on xy plane of line in plot3?

use surfc function but you need a grid in x and y directions

Shadow on xy plane of line in plot3?

use surfc function but you need a grid in x and y directions

2 years ago | 0

Answered

Least squares regression to find coefficients

one solution is: [length(x) sum(x); sum(x) sum(x.^2)]\[sum(y) ; sum(x.*y)]

Least squares regression to find coefficients

one solution is: [length(x) sum(x); sum(x) sum(x.^2)]\[sum(y) ; sum(x.*y)]

2 years ago | 0

Answered

How to plot this eqaution

t=0:.001:1.0; s4 = cos(80*pi*t-10*pi).*(t>0.5 && t<=1.0);

How to plot this eqaution

t=0:.001:1.0; s4 = cos(80*pi*t-10*pi).*(t>0.5 && t<=1.0);

2 years ago | 1

| accepted

Answered

how can we solve non-linear equations like this via MATLAB, I am trying to solve it by using following program but it shows error, shown below in the pic? Thanks in advance.

eqns = [2*u + v == 0, u - v == 1]; S = solve(eqns,[u v]) clear syms a1 a2 a3 a4 eqn1 = cos(a1)+cos(a2)+ cos(a3)+ cos(a4) ==3...

how can we solve non-linear equations like this via MATLAB, I am trying to solve it by using following program but it shows error, shown below in the pic? Thanks in advance.

eqns = [2*u + v == 0, u - v == 1]; S = solve(eqns,[u v]) clear syms a1 a2 a3 a4 eqn1 = cos(a1)+cos(a2)+ cos(a3)+ cos(a4) ==3...

2 years ago | 0

Answered

Why is there a difference in the error when using "syms approach" and "@(x) approach" while defining functions in MATLAB?

Method 2 is an approximate method for finding the derivative of a function

Why is there a difference in the error when using "syms approach" and "@(x) approach" while defining functions in MATLAB?

Method 2 is an approximate method for finding the derivative of a function

2 years ago | 0

Answered

how can we solve non-linear equations like this via MATLAB, I am trying to solve it by using following program but it shows error, shown below in the pic? Thanks in advance.

You have used cos function and your equations are not linear.

how can we solve non-linear equations like this via MATLAB, I am trying to solve it by using following program but it shows error, shown below in the pic? Thanks in advance.

You have used cos function and your equations are not linear.

2 years ago | 0

Answered

Writing data into a text file - fprintf

You should use variables like ReactionTime as global Use this code after the function definition: global ReactionTime cd Use ...

Writing data into a text file - fprintf

You should use variables like ReactionTime as global Use this code after the function definition: global ReactionTime cd Use ...

2 years ago | 0

Answered

How to generate a matrix with assigned probability?

% x is the probability of 1 % m rows and n columns A=binornd(1,x,n,m)'; % another random matrix A=binornd(1,x,n,m)';

How to generate a matrix with assigned probability?

% x is the probability of 1 % m rows and n columns A=binornd(1,x,n,m)'; % another random matrix A=binornd(1,x,n,m)';

2 years ago | 1

Answered

Index from one vector to different sized vector

% v1 the first vector % v2 the matrix [~, ~, i2] = intersect(v1, v2(:,1)); newMatrix = v2(t2,:);

Index from one vector to different sized vector

% v1 the first vector % v2 the matrix [~, ~, i2] = intersect(v1, v2(:,1)); newMatrix = v2(t2,:);

2 years ago | 0

Answered

Roll a 6-sided die until you have rolled a total of 25 6's.

find(cumsum(randi(6,1,1000)==6)==25,1)

Roll a 6-sided die until you have rolled a total of 25 6's.

find(cumsum(randi(6,1,1000)==6)==25,1)

2 years ago | 0

Answered

calling a function in a different script.

One solution is that you can use this command at the top of the files that use 'r' global r; Just after function definition...

calling a function in a different script.

One solution is that you can use this command at the top of the files that use 'r' global r; Just after function definition...

2 years ago | 0

Answered

Why does my code output answers in log?

Use double(solve([1000000==300*((((1+0.08/12)^(n+1)/(0.08/12)-1)))])) to solve this financial problem (interest rate)

Why does my code output answers in log?

Use double(solve([1000000==300*((((1+0.08/12)^(n+1)/(0.08/12)-1)))])) to solve this financial problem (interest rate)

2 years ago | 1

| accepted

Answered

How to return an array to single value?

The size of x is different from G and Tamb

How to return an array to single value?

The size of x is different from G and Tamb

2 years ago | 0

Answered

Plotting functions using loop

lambda=1; gamma1=0.3; n=0:1:15; P1 = (lambda.^n)./(lambda+gamma1).^(n+1)); plot(n, P1);

Plotting functions using loop

lambda=1; gamma1=0.3; n=0:1:15; P1 = (lambda.^n)./(lambda+gamma1).^(n+1)); plot(n, P1);

2 years ago | 0

| accepted

Answered

Negative indexing of an array

There is no non-positive indexing in Matlab. you can use x(end) for the last member, x(end-1) the member before the last membe...

Negative indexing of an array

There is no non-positive indexing in Matlab. you can use x(end) for the last member, x(end-1) the member before the last membe...

2 years ago | 0

Answered

How i can write this in matlab in optimized form using intermediate variables????

sy = sin(y); asy = abs(sy); xt = x + tan(y); xtn = x + log(abs(tan(y))); tx = 2*x+sy^2; ot =1/3; R1 = abs(x)*xt/(50*x^2+as...

How i can write this in matlab in optimized form using intermediate variables????

sy = sin(y); asy = abs(sy); xt = x + tan(y); xtn = x + log(abs(tan(y))); tx = 2*x+sy^2; ot =1/3; R1 = abs(x)*xt/(50*x^2+as...

2 years ago | 0

Answered

How i can write this in matlab??? x=-1.75*10^-3; y=3.1*pi;

R1 = abs(x).*(x+tan(y))./(50*x.^2+abs(sin(y))).^(1/3)+(5*x.^2+abs(sin(y))).^2.2./(x.^2 .* (x+tan(y)).^4); R2 = sinh(sqrt(2*x+(s...

How i can write this in matlab??? x=-1.75*10^-3; y=3.1*pi;

R1 = abs(x).*(x+tan(y))./(50*x.^2+abs(sin(y))).^(1/3)+(5*x.^2+abs(sin(y))).^2.2./(x.^2 .* (x+tan(y)).^4); R2 = sinh(sqrt(2*x+(s...

2 years ago | 1

| accepted

Answered

Number of odd numbers in an array

function n = myNOdds(x) n = sum(mod(x,2)==1); end

Number of odd numbers in an array

function n = myNOdds(x) n = sum(mod(x,2)==1); end

2 years ago | 1

| accepted

Answered

Output of a for loop

You can use this code: %%Acting Forces on the beam and position F2=(-4); x2=0.4; L=1; %Constant EI Assumed 100 kN.m^2 (fr...

Output of a for loop

You can use this code: %%Acting Forces on the beam and position F2=(-4); x2=0.4; L=1; %Constant EI Assumed 100 kN.m^2 (fr...

2 years ago | 0

| accepted

Answered

I'm trying to get a vector from a loop without doing the linspace function

vector = zeros(1,5); j = 1; for i = 0:1.25:5; vector(j) = i; j = j+ 1; end disp(vector)

I'm trying to get a vector from a loop without doing the linspace function

vector = zeros(1,5); j = 1; for i = 0:1.25:5; vector(j) = i; j = j+ 1; end disp(vector)

2 years ago | 0

Answered

Graph line not showing

Several issues in your code: 1- it has only one point (use plot(x, y) ) 2- The angle should be in radians not degrees. For ang...

Graph line not showing

Several issues in your code: 1- it has only one point (use plot(x, y) ) 2- The angle should be in radians not degrees. For ang...

2 years ago | 0

Answered

How do I write the following in matlab ?

H1 = (x.*(1+x.^2).*(1+2*x).^2).^2.3 ./ log(abs(cot(y))) + (log(abs(cot(y)))-x) ./(x.*(1+x.^2).*(1+2*x).^2); R2 = sinh(sqrt(2*x+...

How do I write the following in matlab ?

H1 = (x.*(1+x.^2).*(1+2*x).^2).^2.3 ./ log(abs(cot(y))) + (log(abs(cot(y)))-x) ./(x.*(1+x.^2).*(1+2*x).^2); R2 = sinh(sqrt(2*x+...

2 years ago | 0

Answered

Can you help me write the following in matlab ?

H1 = (x*(1+x^2)*(1+2*x)^2)^2.3 / -log(abs(tan(y))) + (-log(abs(tan(y)))-x) /(x*(1+x^2)*(1+2*x)^2); R2 = sinh(sqrt(2*x+(sin(y)^2...

Can you help me write the following in matlab ?

H1 = (x*(1+x^2)*(1+2*x)^2)^2.3 / -log(abs(tan(y))) + (-log(abs(tan(y)))-x) /(x*(1+x^2)*(1+2*x)^2); R2 = sinh(sqrt(2*x+(sin(y)^2...

2 years ago | 0

Answered

How do I write the following in matlab ?

H1 = (x*(1+x^2)*(1+2*x)^2)^2.3 / -log(abs(tan(y))) + (-log(abs(tan(y)))-x) /(x*(1+x^2)*(1+2*x)^2); R2 = sinh(sqrt(2*x+(sin(y)^2...

How do I write the following in matlab ?

H1 = (x*(1+x^2)*(1+2*x)^2)^2.3 / -log(abs(tan(y))) + (-log(abs(tan(y)))-x) /(x*(1+x^2)*(1+2*x)^2); R2 = sinh(sqrt(2*x+(sin(y)^2...

2 years ago | 0