Category: Matlab
Category Archives: Matlab
Shooting Method with Secant Method
Hi all,
I am working on a problem to solve a second order differential equation. I am using the numerical method ‘the shooting method’ and I need to perform iterations to find the initial value of the slope. To do this I am using the secant method. My intial values to start the shooting method for z are -4 and 4. From this is get the corresponding y values of -65.025 (3dp) and 106.062 (3dp) respectively. I am aiming to find the value of z when y = 0. Thus, I proceed to the secant method to find the value of ‘z’ when y = 0;
The formula for secant method is:
z2 = z1 – (y(z1) – 0)*(z1 – z2)/(y(z1 – y(z0))
I want to make a loop where this updates: Hence:
z0 = z1
z1 = z2
y(z0) = y(z1)
y(z1) = y(z2)
So, the next iteration is:
z3 = z2 – (y(z2) – 0)*(z2 – z21/(y(z2 – y(z2))
The thing is I now need to compute y(z2). I can do this, but it would meaning copying and pasting another block of code. Thus, my question is how to make the algorithm in MATLAB so that I can perform the desired number of iterations I want within the for loop? Rather than copying and pasting the code below over and over again until I reach a satisfactory point of convergence?
Here is my code:
clear, clc, close all
format longG
% Structural Properties
E = 2.1E+08;
Ic = 22530/100^4;
Ib = 19460/100^4;
Ac = 168/100^2;
h = 0.5;
r = 1;
Gi = (1*E*Ib/10);
Ci = 1/2*(E*Ic/h);
g = Gi/Ci;
K = (6*g + 1 + r);
V = [0 0 0 0 0 35 0 0 0 0 0 25 0 0 0 0 0 15 0 0 0 0 0 5 0];
%Initial Conditions 1
y = 0
z = -4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
q0 = y(end)
p0 = z(1)
end
q0 = y(end)
p0 = z(1)
%Initial Conditions 2
y = 0
z = 4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
end
q1 = y(end)
p1 = z(1)
% Secant Method
p2 = p1 – (q1 – 0)*(p1 – p0)/(q1 -q0)
I have left the secant method formula outside the loop, because I am unsure how to include it in the loop to perform the iterations I previously explained.
I understand that this is quite a long question. So thank you in advance for any help. However, you guys on here are great, so I hoping its not too tedious for you.
Many thanks,
ScottHi all,
I am working on a problem to solve a second order differential equation. I am using the numerical method ‘the shooting method’ and I need to perform iterations to find the initial value of the slope. To do this I am using the secant method. My intial values to start the shooting method for z are -4 and 4. From this is get the corresponding y values of -65.025 (3dp) and 106.062 (3dp) respectively. I am aiming to find the value of z when y = 0. Thus, I proceed to the secant method to find the value of ‘z’ when y = 0;
The formula for secant method is:
z2 = z1 – (y(z1) – 0)*(z1 – z2)/(y(z1 – y(z0))
I want to make a loop where this updates: Hence:
z0 = z1
z1 = z2
y(z0) = y(z1)
y(z1) = y(z2)
So, the next iteration is:
z3 = z2 – (y(z2) – 0)*(z2 – z21/(y(z2 – y(z2))
The thing is I now need to compute y(z2). I can do this, but it would meaning copying and pasting another block of code. Thus, my question is how to make the algorithm in MATLAB so that I can perform the desired number of iterations I want within the for loop? Rather than copying and pasting the code below over and over again until I reach a satisfactory point of convergence?
Here is my code:
clear, clc, close all
format longG
% Structural Properties
E = 2.1E+08;
Ic = 22530/100^4;
Ib = 19460/100^4;
Ac = 168/100^2;
h = 0.5;
r = 1;
Gi = (1*E*Ib/10);
Ci = 1/2*(E*Ic/h);
g = Gi/Ci;
K = (6*g + 1 + r);
V = [0 0 0 0 0 35 0 0 0 0 0 25 0 0 0 0 0 15 0 0 0 0 0 5 0];
%Initial Conditions 1
y = 0
z = -4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
q0 = y(end)
p0 = z(1)
end
q0 = y(end)
p0 = z(1)
%Initial Conditions 2
y = 0
z = 4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
end
q1 = y(end)
p1 = z(1)
% Secant Method
p2 = p1 – (q1 – 0)*(p1 – p0)/(q1 -q0)
I have left the secant method formula outside the loop, because I am unsure how to include it in the loop to perform the iterations I previously explained.
I understand that this is quite a long question. So thank you in advance for any help. However, you guys on here are great, so I hoping its not too tedious for you.
Many thanks,
Scott Hi all,
I am working on a problem to solve a second order differential equation. I am using the numerical method ‘the shooting method’ and I need to perform iterations to find the initial value of the slope. To do this I am using the secant method. My intial values to start the shooting method for z are -4 and 4. From this is get the corresponding y values of -65.025 (3dp) and 106.062 (3dp) respectively. I am aiming to find the value of z when y = 0. Thus, I proceed to the secant method to find the value of ‘z’ when y = 0;
The formula for secant method is:
z2 = z1 – (y(z1) – 0)*(z1 – z2)/(y(z1 – y(z0))
I want to make a loop where this updates: Hence:
z0 = z1
z1 = z2
y(z0) = y(z1)
y(z1) = y(z2)
So, the next iteration is:
z3 = z2 – (y(z2) – 0)*(z2 – z21/(y(z2 – y(z2))
The thing is I now need to compute y(z2). I can do this, but it would meaning copying and pasting another block of code. Thus, my question is how to make the algorithm in MATLAB so that I can perform the desired number of iterations I want within the for loop? Rather than copying and pasting the code below over and over again until I reach a satisfactory point of convergence?
Here is my code:
clear, clc, close all
format longG
% Structural Properties
E = 2.1E+08;
Ic = 22530/100^4;
Ib = 19460/100^4;
Ac = 168/100^2;
h = 0.5;
r = 1;
Gi = (1*E*Ib/10);
Ci = 1/2*(E*Ic/h);
g = Gi/Ci;
K = (6*g + 1 + r);
V = [0 0 0 0 0 35 0 0 0 0 0 25 0 0 0 0 0 15 0 0 0 0 0 5 0];
%Initial Conditions 1
y = 0
z = -4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
q0 = y(end)
p0 = z(1)
end
q0 = y(end)
p0 = z(1)
%Initial Conditions 2
y = 0
z = 4
for i = 1:24
if i == 6 || i == 12 || i == 18
F(i) = h*(V(i) + V(i+6))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
else F(i) = 0;
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h;
end
if i == 24
F(i) = h*(V(i))/(4*Ci);
z(i+1) = z(i) + ((F(i) – K*z(i) + y(i))/(-z(i)))*h;
y(i+1) = y(i) + z(i)*h
end
end
q1 = y(end)
p1 = z(1)
% Secant Method
p2 = p1 – (q1 – 0)*(p1 – p0)/(q1 -q0)
I have left the secant method formula outside the loop, because I am unsure how to include it in the loop to perform the iterations I previously explained.
I understand that this is quite a long question. So thank you in advance for any help. However, you guys on here are great, so I hoping its not too tedious for you.
Many thanks,
Scott for loop MATLAB Answers — New Questions
i try to do quadratic interpolation with 3 initial guesses. when i run the code it do nothing
d=input(‘Please enter a function f(x): ‘);
x0=input(‘Please give a initial guess of x0: ‘);
x1=input(‘Please give a initial guess of x1: ‘);
x2=input(‘Please give a initial guess of x2: ‘);
signum=input(‘Please enter the prespecified error: ‘);
f=inline(d);
i=1;
x3=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
x(i)=x3;
error(i)=9999;
es=(0.5*10^(2-signum));
while error(i)>=es
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
a=x(i+1);
if f(a)>f(x0)
if f(a)>f(x2)
x0=x1;
x1=x(i+1);
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
elseif f(a)<f(x2)
x2=x1;
x1=x(i+1);
end
end
error(i+1)=abs((((x(i+1)-x(i))/(x(i+1)))*100));
i=i+1;
endd=input(‘Please enter a function f(x): ‘);
x0=input(‘Please give a initial guess of x0: ‘);
x1=input(‘Please give a initial guess of x1: ‘);
x2=input(‘Please give a initial guess of x2: ‘);
signum=input(‘Please enter the prespecified error: ‘);
f=inline(d);
i=1;
x3=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
x(i)=x3;
error(i)=9999;
es=(0.5*10^(2-signum));
while error(i)>=es
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
a=x(i+1);
if f(a)>f(x0)
if f(a)>f(x2)
x0=x1;
x1=x(i+1);
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
elseif f(a)<f(x2)
x2=x1;
x1=x(i+1);
end
end
error(i+1)=abs((((x(i+1)-x(i))/(x(i+1)))*100));
i=i+1;
end d=input(‘Please enter a function f(x): ‘);
x0=input(‘Please give a initial guess of x0: ‘);
x1=input(‘Please give a initial guess of x1: ‘);
x2=input(‘Please give a initial guess of x2: ‘);
signum=input(‘Please enter the prespecified error: ‘);
f=inline(d);
i=1;
x3=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
x(i)=x3;
error(i)=9999;
es=(0.5*10^(2-signum));
while error(i)>=es
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
a=x(i+1);
if f(a)>f(x0)
if f(a)>f(x2)
x0=x1;
x1=x(i+1);
x(i+1)=(f(x0)*(x1^2-x2^2)+f(x1)*(x2^2-x0^2)+f(x2)*(x0^2-x1^2))/(2*f(x0)*(x1-x2)+2*f(x1)*(x2-x0)+2*f(x2)*(x0-x1));
elseif f(a)<f(x2)
x2=x1;
x1=x(i+1);
end
end
error(i+1)=abs((((x(i+1)-x(i))/(x(i+1)))*100));
i=i+1;
end quadratic polynomial interpolation curve fitting MATLAB Answers — New Questions
MATLAB FFT bin size
I am attemping to create an FFT function that allows me to set the frequency range of the FFT, the number of bins, and windowing type. For the frequnecy range, my logic is to use a low-pass filter. If I add a filter, does it make sense to have windowing? How am I able to set a distinct number of bins in the FFT, it seems that automaticcaly the number of bins is incredibly high (I am collecting data at 48 kHz for about 90 seconds). I would like the bin width to be around 1 Hz instead of ~.01 which it currently is. How can I change this? We have another program that is able to achieve this, so I know that it is possible, but is this program cutting out data to achieve this?I am attemping to create an FFT function that allows me to set the frequency range of the FFT, the number of bins, and windowing type. For the frequnecy range, my logic is to use a low-pass filter. If I add a filter, does it make sense to have windowing? How am I able to set a distinct number of bins in the FFT, it seems that automaticcaly the number of bins is incredibly high (I am collecting data at 48 kHz for about 90 seconds). I would like the bin width to be around 1 Hz instead of ~.01 which it currently is. How can I change this? We have another program that is able to achieve this, so I know that it is possible, but is this program cutting out data to achieve this? I am attemping to create an FFT function that allows me to set the frequency range of the FFT, the number of bins, and windowing type. For the frequnecy range, my logic is to use a low-pass filter. If I add a filter, does it make sense to have windowing? How am I able to set a distinct number of bins in the FFT, it seems that automaticcaly the number of bins is incredibly high (I am collecting data at 48 kHz for about 90 seconds). I would like the bin width to be around 1 Hz instead of ~.01 which it currently is. How can I change this? We have another program that is able to achieve this, so I know that it is possible, but is this program cutting out data to achieve this? fft, signal processing, digital signal processing, filter MATLAB Answers — New Questions
Passing Command Like Arguments to a compiled Simulink Model
Hello,
I’d like to pass command line arguments to a compiled GRT Simulink model. The idea is to overwrite pre defined variables used in the model, e.g. in a Constant block. So far I could not find any information on this.
Thank you in advance for your help!
Best,
LeonHello,
I’d like to pass command line arguments to a compiled GRT Simulink model. The idea is to overwrite pre defined variables used in the model, e.g. in a Constant block. So far I could not find any information on this.
Thank you in advance for your help!
Best,
Leon Hello,
I’d like to pass command line arguments to a compiled GRT Simulink model. The idea is to overwrite pre defined variables used in the model, e.g. in a Constant block. So far I could not find any information on this.
Thank you in advance for your help!
Best,
Leon simulink, binary, compilation, command line, arguments MATLAB Answers — New Questions
Can’t update Matlab from 2019b to 2023b under Win10
I’ve downloaded the 2023 update package for updating my off line Matlab system. I follow the instructions. When I start Mathworksupdateinstaller, I get a blue screen with a window schetch in the right lower corner. Nothing more. When I brake out after a while, I get told ‘No permissions’. I have succesfully logged in both as admin and with my userThe cv-log contains more than 800 lines of this:
{"logTime": "0607/084838", "correlationVector":"sFXPYkuspD/7W0NNS8WKSp","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084840", "correlationVector":"JS5fPs9bfqSIcuFCgEp0BV","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084844", "correlationVector":"wzHgPJW0SFOni4bfI4cC+U","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094838", "correlationVector":"kTx5PeWO2xUCkmNlTAJoZG","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094840", "correlationVector":"1cwc0BKbLtDQokkVOAAh2o","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094844", "correlationVector":"33kSEtVRqwHhtCgacLyn8J","action":"EXTENSION_UPDATER", "result":""}
What is the issue?I’ve downloaded the 2023 update package for updating my off line Matlab system. I follow the instructions. When I start Mathworksupdateinstaller, I get a blue screen with a window schetch in the right lower corner. Nothing more. When I brake out after a while, I get told ‘No permissions’. I have succesfully logged in both as admin and with my userThe cv-log contains more than 800 lines of this:
{"logTime": "0607/084838", "correlationVector":"sFXPYkuspD/7W0NNS8WKSp","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084840", "correlationVector":"JS5fPs9bfqSIcuFCgEp0BV","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084844", "correlationVector":"wzHgPJW0SFOni4bfI4cC+U","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094838", "correlationVector":"kTx5PeWO2xUCkmNlTAJoZG","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094840", "correlationVector":"1cwc0BKbLtDQokkVOAAh2o","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094844", "correlationVector":"33kSEtVRqwHhtCgacLyn8J","action":"EXTENSION_UPDATER", "result":""}
What is the issue? I’ve downloaded the 2023 update package for updating my off line Matlab system. I follow the instructions. When I start Mathworksupdateinstaller, I get a blue screen with a window schetch in the right lower corner. Nothing more. When I brake out after a while, I get told ‘No permissions’. I have succesfully logged in both as admin and with my userThe cv-log contains more than 800 lines of this:
{"logTime": "0607/084838", "correlationVector":"sFXPYkuspD/7W0NNS8WKSp","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084840", "correlationVector":"JS5fPs9bfqSIcuFCgEp0BV","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/084844", "correlationVector":"wzHgPJW0SFOni4bfI4cC+U","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094838", "correlationVector":"kTx5PeWO2xUCkmNlTAJoZG","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094840", "correlationVector":"1cwc0BKbLtDQokkVOAAh2o","action":"EXTENSION_UPDATER", "result":""}
{"logTime": "0607/094844", "correlationVector":"33kSEtVRqwHhtCgacLyn8J","action":"EXTENSION_UPDATER", "result":""}
What is the issue? upgrade, offline, r2019b r2023b, win10 MATLAB Answers — New Questions
Blank Documentation 2023b
Recently we have some upgrade version from 2020a to 2023b.
Some users complain that they lost access to the documentation from help. We discover that the product documentation is with 2023a possible to run by web – to reduce the installation footprint – so we understand that, and to avoid install so big package with documentation we wanted to allow users connect to the documentation from their devices. As of documentation which I checked we provided proxy server and test connection is success. From web browser the communication is working for users also and they see all the functions. But when they want to use the help center in the Matlab the page is still blank :Recently we have some upgrade version from 2020a to 2023b.
Some users complain that they lost access to the documentation from help. We discover that the product documentation is with 2023a possible to run by web – to reduce the installation footprint – so we understand that, and to avoid install so big package with documentation we wanted to allow users connect to the documentation from their devices. As of documentation which I checked we provided proxy server and test connection is success. From web browser the communication is working for users also and they see all the functions. But when they want to use the help center in the Matlab the page is still blank : Recently we have some upgrade version from 2020a to 2023b.
Some users complain that they lost access to the documentation from help. We discover that the product documentation is with 2023a possible to run by web – to reduce the installation footprint – so we understand that, and to avoid install so big package with documentation we wanted to allow users connect to the documentation from their devices. As of documentation which I checked we provided proxy server and test connection is success. From web browser the communication is working for users also and they see all the functions. But when they want to use the help center in the Matlab the page is still blank : documentation, help, proxy, web MATLAB Answers — New Questions
Different MFCC obtained from audioFeatureExtractor and MFCC function
Hi,
I’m trying to use the "audioFeatureExtractor" and the MFCC function to get the MFCC data from an audio sample but noticed the coefficients are different. I´m assuming some default settings are different between these codes but cannot figure exactly what the difference is. Could you please help? Please find below a simple script to provide more detail. I’m comparing "MFCC1" MFCC2". I´ve tried several .wav and .m4a files but the MFCCs were never the same so I´m just using a generic "xxxxxxx" for file name.
[audioIn,fs] = audioread("xxxxxxx");
win1 = hamming(round(0.03*fs),"periodic");
win2 = round(0.015*fs);
aFE = audioFeatureExtractor(SampleRate=fs,Window=win1,OverlapLength=win2,mfcc=1);
features = extract(aFE,audioIn);
idx = info(aFE);
MFCC1 = features(:,idx.mfcc);
MFCC2 = mfcc(audioIn,fs,"LogEnergy","ignore","Window",win1,"Overlaplength",win2,"NumCoeffs",13);Hi,
I’m trying to use the "audioFeatureExtractor" and the MFCC function to get the MFCC data from an audio sample but noticed the coefficients are different. I´m assuming some default settings are different between these codes but cannot figure exactly what the difference is. Could you please help? Please find below a simple script to provide more detail. I’m comparing "MFCC1" MFCC2". I´ve tried several .wav and .m4a files but the MFCCs were never the same so I´m just using a generic "xxxxxxx" for file name.
[audioIn,fs] = audioread("xxxxxxx");
win1 = hamming(round(0.03*fs),"periodic");
win2 = round(0.015*fs);
aFE = audioFeatureExtractor(SampleRate=fs,Window=win1,OverlapLength=win2,mfcc=1);
features = extract(aFE,audioIn);
idx = info(aFE);
MFCC1 = features(:,idx.mfcc);
MFCC2 = mfcc(audioIn,fs,"LogEnergy","ignore","Window",win1,"Overlaplength",win2,"NumCoeffs",13); Hi,
I’m trying to use the "audioFeatureExtractor" and the MFCC function to get the MFCC data from an audio sample but noticed the coefficients are different. I´m assuming some default settings are different between these codes but cannot figure exactly what the difference is. Could you please help? Please find below a simple script to provide more detail. I’m comparing "MFCC1" MFCC2". I´ve tried several .wav and .m4a files but the MFCCs were never the same so I´m just using a generic "xxxxxxx" for file name.
[audioIn,fs] = audioread("xxxxxxx");
win1 = hamming(round(0.03*fs),"periodic");
win2 = round(0.015*fs);
aFE = audioFeatureExtractor(SampleRate=fs,Window=win1,OverlapLength=win2,mfcc=1);
features = extract(aFE,audioIn);
idx = info(aFE);
MFCC1 = features(:,idx.mfcc);
MFCC2 = mfcc(audioIn,fs,"LogEnergy","ignore","Window",win1,"Overlaplength",win2,"NumCoeffs",13); mfcc, audiofeatureextractor MATLAB Answers — New Questions
readtable can read Excel XLS but not XLSX on OneDrive?
Hello!
Unable to open file ‘C:UsersjuansOneDriveJuanMatlabBook5.xlsx’ as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
A while ago, it was identified that there was an issue with OneDrive blocking Excel files, and you have to close the file on Excel in order for MATLAB to open it, which is very inconvenient for the workflow. Another workaround I found is to use XLS, which is also not always a good solution. I could not find whether this issue has been solved.
What is the current status of this issue? (I have 2023a)
Cheers!Hello!
Unable to open file ‘C:UsersjuansOneDriveJuanMatlabBook5.xlsx’ as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
A while ago, it was identified that there was an issue with OneDrive blocking Excel files, and you have to close the file on Excel in order for MATLAB to open it, which is very inconvenient for the workflow. Another workaround I found is to use XLS, which is also not always a good solution. I could not find whether this issue has been solved.
What is the current status of this issue? (I have 2023a)
Cheers! Hello!
Unable to open file ‘C:UsersjuansOneDriveJuanMatlabBook5.xlsx’ as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
A while ago, it was identified that there was an issue with OneDrive blocking Excel files, and you have to close the file on Excel in order for MATLAB to open it, which is very inconvenient for the workflow. Another workaround I found is to use XLS, which is also not always a good solution. I could not find whether this issue has been solved.
What is the current status of this issue? (I have 2023a)
Cheers! onedrive, excel, readtable MATLAB Answers — New Questions
import txt file in matlab
I failed to import the attached txt which I need it to be read with the below function
which converts it into another data shape. I do not know what seems to be the problem. Any ideas?
function FBW = get_FBW(Ftable)
d = importdata(Ftable);
for i = 2:size(d.data,1) % do each row separately
rowdat = d.data(i,:);
rowdat = rowdat(~isnan(rowdat));
col = (rowdat(1:2:end-1));
val = rowdat(2:2:end);
nframes = col(end);
FBW(i-1,:) = zeros(1,nframes);
for j = 2:length(col)
if col(j) – col(j-1) >0
slope = (val(j) – val(j-1)) ./ (col(j) – col(j-1));
for k = 0:col(j)-col(j-1)
FBW(i-1, (col(j-1)+k)) = val((j-1)) + k*slope;
end
end
end
endI failed to import the attached txt which I need it to be read with the below function
which converts it into another data shape. I do not know what seems to be the problem. Any ideas?
function FBW = get_FBW(Ftable)
d = importdata(Ftable);
for i = 2:size(d.data,1) % do each row separately
rowdat = d.data(i,:);
rowdat = rowdat(~isnan(rowdat));
col = (rowdat(1:2:end-1));
val = rowdat(2:2:end);
nframes = col(end);
FBW(i-1,:) = zeros(1,nframes);
for j = 2:length(col)
if col(j) – col(j-1) >0
slope = (val(j) – val(j-1)) ./ (col(j) – col(j-1));
for k = 0:col(j)-col(j-1)
FBW(i-1, (col(j-1)+k)) = val((j-1)) + k*slope;
end
end
end
end I failed to import the attached txt which I need it to be read with the below function
which converts it into another data shape. I do not know what seems to be the problem. Any ideas?
function FBW = get_FBW(Ftable)
d = importdata(Ftable);
for i = 2:size(d.data,1) % do each row separately
rowdat = d.data(i,:);
rowdat = rowdat(~isnan(rowdat));
col = (rowdat(1:2:end-1));
val = rowdat(2:2:end);
nframes = col(end);
FBW(i-1,:) = zeros(1,nframes);
for j = 2:length(col)
if col(j) – col(j-1) >0
slope = (val(j) – val(j-1)) ./ (col(j) – col(j-1));
for k = 0:col(j)-col(j-1)
FBW(i-1, (col(j-1)+k)) = val((j-1)) + k*slope;
end
end
end
end import text as matrix MATLAB Answers — New Questions
In simulink for Tms320F28388D controller for cpu 1 and cpu 2 it is possible to generate the code but when i trying to generate code with cortex M4 i am unable to generate it
I tried and generate codes for cpu1 and cpu 2 but while i am trying to generate for M4 i am facing the issueI tried and generate codes for cpu1 and cpu 2 but while i am trying to generate for M4 i am facing the issue I tried and generate codes for cpu1 and cpu 2 but while i am trying to generate for M4 i am facing the issue nonlinear MATLAB Answers — New Questions
How to read and plot Rinex messages?
How to read and plot rinex messages like longitude, latitude, time, no.of SV(number of satellites) and GDOP from a raw file (obs/nav or ubx file) recorded/saved on my pc using matlab?How to read and plot rinex messages like longitude, latitude, time, no.of SV(number of satellites) and GDOP from a raw file (obs/nav or ubx file) recorded/saved on my pc using matlab? How to read and plot rinex messages like longitude, latitude, time, no.of SV(number of satellites) and GDOP from a raw file (obs/nav or ubx file) recorded/saved on my pc using matlab? read and plot rinex messages like longitude, latitude MATLAB Answers — New Questions
deal signal in simulink
You can see that my original signal is the yellow line in the picture, similar to a series of pulses. I want to process the original signal to look like the red in the picture, a ramp signal with a class period. After a peak, it immediately decreases to 0 and then linearly increases from 0 to a new peak
i use matlab function in simulink ,but can‘t work like i expect
my english is not that good ,if you have any question,please let me knowYou can see that my original signal is the yellow line in the picture, similar to a series of pulses. I want to process the original signal to look like the red in the picture, a ramp signal with a class period. After a peak, it immediately decreases to 0 and then linearly increases from 0 to a new peak
i use matlab function in simulink ,but can‘t work like i expect
my english is not that good ,if you have any question,please let me know You can see that my original signal is the yellow line in the picture, similar to a series of pulses. I want to process the original signal to look like the red in the picture, a ramp signal with a class period. After a peak, it immediately decreases to 0 and then linearly increases from 0 to a new peak
i use matlab function in simulink ,but can‘t work like i expect
my english is not that good ,if you have any question,please let me know simulink, signal processing MATLAB Answers — New Questions
How to simulate code in symbolic form?
o2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(2));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%I want to run this code for symbolic variables including o2,ain,o4,bin,input_axis,output_axis,naxis,theta1,theta2.
can someone tell how can i do all above calculations in symbolic formo2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(2));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%I want to run this code for symbolic variables including o2,ain,o4,bin,input_axis,output_axis,naxis,theta1,theta2.
can someone tell how can i do all above calculations in symbolic form o2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(2));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%I want to run this code for symbolic variables including o2,ain,o4,bin,input_axis,output_axis,naxis,theta1,theta2.
can someone tell how can i do all above calculations in symbolic form #symbolic, #numerical MATLAB Answers — New Questions
Tricks to increase computational speed for D = (A + A*B).*C
Hello
I am working on computing the time evolution of a distribution. The distribution evolves as follows
g(t + dt) = (g(t) + dt*MAT*g(t)).*exp(-k*dt)
here g and k are column vector of size m*1, MAT is a square matrix of size m*m.
Say i have to evolve it "n" times, the way I have attempted my solution is
g = zeros(m,n)
g(:,1) = g0 % initalising
MAT, k = something pre calculated
for i = 1:1:n
g(:,i+1) = (g(:,i) + dt*MAT*g(:,i) ).*exp(-k*dt)
end
This is the conventional basic way I guess but it takes a long time. How else can I implement the evolution to make it faster.
For perspective the matrices are of the order of 10,000*10,000 and I would like to evolve it for another 5000 ish points
MAT is a mostly a sparse matrix. It has significant non zero diagonal elements and in a given row maybe 50-60 elements are non zero.
Grateful for any suggestions!Hello
I am working on computing the time evolution of a distribution. The distribution evolves as follows
g(t + dt) = (g(t) + dt*MAT*g(t)).*exp(-k*dt)
here g and k are column vector of size m*1, MAT is a square matrix of size m*m.
Say i have to evolve it "n" times, the way I have attempted my solution is
g = zeros(m,n)
g(:,1) = g0 % initalising
MAT, k = something pre calculated
for i = 1:1:n
g(:,i+1) = (g(:,i) + dt*MAT*g(:,i) ).*exp(-k*dt)
end
This is the conventional basic way I guess but it takes a long time. How else can I implement the evolution to make it faster.
For perspective the matrices are of the order of 10,000*10,000 and I would like to evolve it for another 5000 ish points
MAT is a mostly a sparse matrix. It has significant non zero diagonal elements and in a given row maybe 50-60 elements are non zero.
Grateful for any suggestions! Hello
I am working on computing the time evolution of a distribution. The distribution evolves as follows
g(t + dt) = (g(t) + dt*MAT*g(t)).*exp(-k*dt)
here g and k are column vector of size m*1, MAT is a square matrix of size m*m.
Say i have to evolve it "n" times, the way I have attempted my solution is
g = zeros(m,n)
g(:,1) = g0 % initalising
MAT, k = something pre calculated
for i = 1:1:n
g(:,i+1) = (g(:,i) + dt*MAT*g(:,i) ).*exp(-k*dt)
end
This is the conventional basic way I guess but it takes a long time. How else can I implement the evolution to make it faster.
For perspective the matrices are of the order of 10,000*10,000 and I would like to evolve it for another 5000 ish points
MAT is a mostly a sparse matrix. It has significant non zero diagonal elements and in a given row maybe 50-60 elements are non zero.
Grateful for any suggestions! matrix manipulation, ode, speed MATLAB Answers — New Questions
Trying to display text and variable in a single output line. I was initially trying to use disp then a matrix then fprintf
desired output:
The answer is: 800 %
I am trying to display this sentence in a single line of output in the command window. thankyoudesired output:
The answer is: 800 %
I am trying to display this sentence in a single line of output in the command window. thankyou desired output:
The answer is: 800 %
I am trying to display this sentence in a single line of output in the command window. thankyou sentence with variable, text output with varyable MATLAB Answers — New Questions
save tic toc in duration style
Hi all, I would like to save my computational time using tic toc but in format duration (i am trying to use duration but I don’t know how to save it).
Here is my code, so far I just get the time in second, and exact time give me number separate by comas. What I want to get is something like
1 hour 20 second saving in txt file. Do you guys can help me?
close all, clc, clear all
tStart = tic;
a=load(‘PE_201507_LPF7Hz_m5L3.dat’);
plot(a)
tEnd = toc(tStart)
tEnd = toc(tStart);
time_exec=datevec(tEnd./(60*60*24)) %change time in tictoc to
name=sprintf(‘exec_time.txt’)
dlmwrite (name,time_exec);Hi all, I would like to save my computational time using tic toc but in format duration (i am trying to use duration but I don’t know how to save it).
Here is my code, so far I just get the time in second, and exact time give me number separate by comas. What I want to get is something like
1 hour 20 second saving in txt file. Do you guys can help me?
close all, clc, clear all
tStart = tic;
a=load(‘PE_201507_LPF7Hz_m5L3.dat’);
plot(a)
tEnd = toc(tStart)
tEnd = toc(tStart);
time_exec=datevec(tEnd./(60*60*24)) %change time in tictoc to
name=sprintf(‘exec_time.txt’)
dlmwrite (name,time_exec); Hi all, I would like to save my computational time using tic toc but in format duration (i am trying to use duration but I don’t know how to save it).
Here is my code, so far I just get the time in second, and exact time give me number separate by comas. What I want to get is something like
1 hour 20 second saving in txt file. Do you guys can help me?
close all, clc, clear all
tStart = tic;
a=load(‘PE_201507_LPF7Hz_m5L3.dat’);
plot(a)
tEnd = toc(tStart)
tEnd = toc(tStart);
time_exec=datevec(tEnd./(60*60*24)) %change time in tictoc to
name=sprintf(‘exec_time.txt’)
dlmwrite (name,time_exec); tic toc, duration MATLAB Answers — New Questions
How to plot time from 0-24?
Dear All,
I have time :
Description:Time of GPS measurement (GPS seconds)
Data Type: double
Units: s
Valid Range: 0, 99999
How can I plot it from 0-24 UT and LT?
Best,
AraDear All,
I have time :
Description:Time of GPS measurement (GPS seconds)
Data Type: double
Units: s
Valid Range: 0, 99999
How can I plot it from 0-24 UT and LT?
Best,
Ara Dear All,
I have time :
Description:Time of GPS measurement (GPS seconds)
Data Type: double
Units: s
Valid Range: 0, 99999
How can I plot it from 0-24 UT and LT?
Best,
Ara time MATLAB Answers — New Questions
ODE15i DAE Warning:Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (0.000000e+00) at time t.
I’m solving a DAE using ode15i. I use the same syntaxs as the example of Robertson in Matlab help
https://it.mathworks.com/help/matlab/ref/ode15i.html?s_tid=doc_ta
The script is
h = 2/2; % h = L/n, L = 2, n = 2
y0 = [0;-2/h^2;1;2/h^2;1/h;-1/h;1/h;0];
yp0 = [
-2.0000
-0.0545
2.0000
0.0545
0
0
0
0];
%The initial conditions must be "consistent", meaning
% that f(T0,Y0,YP0)=0
% With y0 and yp0 given, Node_2(0,y0,yp0) = [0 … 0] so initial conditions
% are consistent
%opt = odeset(‘RelTol’,10^-3,’AbsTol’,10^-6,’Jacobian’,@Jac_Node_2); %Optionnal
tspan = [0 4];
[t,y] = ode15i(@Node_2,tspan,y0,yp0);%,opt);
And the odefunction is :
function res = Node_2(t,y,yp)
h = 2/2;
m = 25000*0.12^2/9.81;
res = [
(y(3) – y(1))/h – y(5);
(y(6)-y(5))/h – m*yp(2);
y(1);
yp(1) – y(2);
(y(8)-y(3))/h – y(6);
(y(7)-y(6))/h – m*yp(4);
yp(3) – y(4);
y(8)
];
end
The problem is that i get the following error :
Warning: Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (0.000000e+00) at time t.
I tried to change the relative and absolute error tolerance ‘RelTol’ and ‘AbsTol’ but nothing change for every possible values, i tried to provide the Jacobian matrix but again it gives the same error.
The initial conditions are consistent because Node_2(0,y0,yp0) = [0 … 0]
I would like to understand why there is this error so that i can find a solution, or i you spot the error in the code i would appreciate.I’m solving a DAE using ode15i. I use the same syntaxs as the example of Robertson in Matlab help
https://it.mathworks.com/help/matlab/ref/ode15i.html?s_tid=doc_ta
The script is
h = 2/2; % h = L/n, L = 2, n = 2
y0 = [0;-2/h^2;1;2/h^2;1/h;-1/h;1/h;0];
yp0 = [
-2.0000
-0.0545
2.0000
0.0545
0
0
0
0];
%The initial conditions must be "consistent", meaning
% that f(T0,Y0,YP0)=0
% With y0 and yp0 given, Node_2(0,y0,yp0) = [0 … 0] so initial conditions
% are consistent
%opt = odeset(‘RelTol’,10^-3,’AbsTol’,10^-6,’Jacobian’,@Jac_Node_2); %Optionnal
tspan = [0 4];
[t,y] = ode15i(@Node_2,tspan,y0,yp0);%,opt);
And the odefunction is :
function res = Node_2(t,y,yp)
h = 2/2;
m = 25000*0.12^2/9.81;
res = [
(y(3) – y(1))/h – y(5);
(y(6)-y(5))/h – m*yp(2);
y(1);
yp(1) – y(2);
(y(8)-y(3))/h – y(6);
(y(7)-y(6))/h – m*yp(4);
yp(3) – y(4);
y(8)
];
end
The problem is that i get the following error :
Warning: Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (0.000000e+00) at time t.
I tried to change the relative and absolute error tolerance ‘RelTol’ and ‘AbsTol’ but nothing change for every possible values, i tried to provide the Jacobian matrix but again it gives the same error.
The initial conditions are consistent because Node_2(0,y0,yp0) = [0 … 0]
I would like to understand why there is this error so that i can find a solution, or i you spot the error in the code i would appreciate. I’m solving a DAE using ode15i. I use the same syntaxs as the example of Robertson in Matlab help
https://it.mathworks.com/help/matlab/ref/ode15i.html?s_tid=doc_ta
The script is
h = 2/2; % h = L/n, L = 2, n = 2
y0 = [0;-2/h^2;1;2/h^2;1/h;-1/h;1/h;0];
yp0 = [
-2.0000
-0.0545
2.0000
0.0545
0
0
0
0];
%The initial conditions must be "consistent", meaning
% that f(T0,Y0,YP0)=0
% With y0 and yp0 given, Node_2(0,y0,yp0) = [0 … 0] so initial conditions
% are consistent
%opt = odeset(‘RelTol’,10^-3,’AbsTol’,10^-6,’Jacobian’,@Jac_Node_2); %Optionnal
tspan = [0 4];
[t,y] = ode15i(@Node_2,tspan,y0,yp0);%,opt);
And the odefunction is :
function res = Node_2(t,y,yp)
h = 2/2;
m = 25000*0.12^2/9.81;
res = [
(y(3) – y(1))/h – y(5);
(y(6)-y(5))/h – m*yp(2);
y(1);
yp(1) – y(2);
(y(8)-y(3))/h – y(6);
(y(7)-y(6))/h – m*yp(4);
yp(3) – y(4);
y(8)
];
end
The problem is that i get the following error :
Warning: Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (0.000000e+00) at time t.
I tried to change the relative and absolute error tolerance ‘RelTol’ and ‘AbsTol’ but nothing change for every possible values, i tried to provide the Jacobian matrix but again it gives the same error.
The initial conditions are consistent because Node_2(0,y0,yp0) = [0 … 0]
I would like to understand why there is this error so that i can find a solution, or i you spot the error in the code i would appreciate. ode15i, dae, error MATLAB Answers — New Questions
HDL Coder Mult + Add uses DSP48E1 + fabric
Matlab 2023a, HDL Coder ver4.1, and VC707 board. I tried to use Coder on dsp_subsys1 from: https://www.mathworks.com/help/hdlcoder/ug/modeling-efficient-multiplication-and-division-operations-for-fpga-targeting.html
But the workflow advisor always generates adder logic in the fabric, in addition to using a DSP slice. THe resets are configured as synchronous.
I’m basing my last sentence on this: https://www.mathworks.com/matlabcentral/answers/1727185-multiply-and-add-not-correctly-mapping-to-a-single-dsp-slice?s_tid=srchtitle
Help on this would be much appreciated…Matlab 2023a, HDL Coder ver4.1, and VC707 board. I tried to use Coder on dsp_subsys1 from: https://www.mathworks.com/help/hdlcoder/ug/modeling-efficient-multiplication-and-division-operations-for-fpga-targeting.html
But the workflow advisor always generates adder logic in the fabric, in addition to using a DSP slice. THe resets are configured as synchronous.
I’m basing my last sentence on this: https://www.mathworks.com/matlabcentral/answers/1727185-multiply-and-add-not-correctly-mapping-to-a-single-dsp-slice?s_tid=srchtitle
Help on this would be much appreciated… Matlab 2023a, HDL Coder ver4.1, and VC707 board. I tried to use Coder on dsp_subsys1 from: https://www.mathworks.com/help/hdlcoder/ug/modeling-efficient-multiplication-and-division-operations-for-fpga-targeting.html
But the workflow advisor always generates adder logic in the fabric, in addition to using a DSP slice. THe resets are configured as synchronous.
I’m basing my last sentence on this: https://www.mathworks.com/matlabcentral/answers/1727185-multiply-and-add-not-correctly-mapping-to-a-single-dsp-slice?s_tid=srchtitle
Help on this would be much appreciated… multiply add hdl coder MATLAB Answers — New Questions
Assignment of colors in a scatter plot
I have a problem when using the colorbar in my scatter plot. I have a variable called flag, that can have the value 0, 1 or 2 and is used to plot the color of my scatter plot. Furthermore I defined a custom colormap with three colors which are assigned to each flag. The problem that arrises now is that the wrong colors are used in my scatter plot.
For example: Flag 1 is coded with green but the scatter shows it in blue (used for flag 0). I tried to solve it by setting the limits manually but it still has a problem with correctly assigning the colors.
c = colorbar;
c.Ticks = [0, 1, 2];
clim([0 2]);
Heres an example shown:
The first tile shows both data together and the two tiles at the bottom seperately. The colors in the third tile (bottom right) are shown correctly but in the first tile they are shown in a different color.I have a problem when using the colorbar in my scatter plot. I have a variable called flag, that can have the value 0, 1 or 2 and is used to plot the color of my scatter plot. Furthermore I defined a custom colormap with three colors which are assigned to each flag. The problem that arrises now is that the wrong colors are used in my scatter plot.
For example: Flag 1 is coded with green but the scatter shows it in blue (used for flag 0). I tried to solve it by setting the limits manually but it still has a problem with correctly assigning the colors.
c = colorbar;
c.Ticks = [0, 1, 2];
clim([0 2]);
Heres an example shown:
The first tile shows both data together and the two tiles at the bottom seperately. The colors in the third tile (bottom right) are shown correctly but in the first tile they are shown in a different color. I have a problem when using the colorbar in my scatter plot. I have a variable called flag, that can have the value 0, 1 or 2 and is used to plot the color of my scatter plot. Furthermore I defined a custom colormap with three colors which are assigned to each flag. The problem that arrises now is that the wrong colors are used in my scatter plot.
For example: Flag 1 is coded with green but the scatter shows it in blue (used for flag 0). I tried to solve it by setting the limits manually but it still has a problem with correctly assigning the colors.
c = colorbar;
c.Ticks = [0, 1, 2];
clim([0 2]);
Heres an example shown:
The first tile shows both data together and the two tiles at the bottom seperately. The colors in the third tile (bottom right) are shown correctly but in the first tile they are shown in a different color. scatter plot, colorbar, assignment MATLAB Answers — New Questions