Pull up a chair!

Discussions is your place to get to know your peers, tackle the bigger challenges together, and have fun along the way.

  • Want to see the latest updates? Follow the Highlights!
  • Looking for techniques improve your MATLAB or Simulink skills? Tips & Tricks has you covered!
  • Sharing the perfect math joke, pun, or meme? Look no further than Fun!
  • Think there's a channel we need? Tell us more in Ideas


I'm plotting an error with respect to the number of points used.
Now there are three different ways to comput the error, and I always plot the maximal error.
If the maximum is for computation 1, I want the dot in the plot to be red, for computation 2 it should be blue, etc.
How can I achieve this? My data is in a n x 2 matrix
It is crucial to understand that this expression could be used in problems related to engineering, physics, mathematics, or any other aspect of real life.
Typically, Matlab is used to solve PDE and ODE problems. Perhaps users calculated this term 0^0 incorrectly in the process.
>> % Reviewed by Bewar Yousif Ali
>> % How to fix this problem 0^0 in Matlab !?
>> % Mathematically, x^0=1 if x≠0 is equal 1 else undefined(NaN)
>> 0^0
ans =
1
>> f=@(x,y) x^y;
>> f(0,0)
ans =
1
>> v=[2 0 5 -1];
>> v.^0
ans =
1 1 1 1
What amazing animations can be created with no more than 2000 characters of MATLAB code? Check out our GALLERY from the MATLAB Flipbook Mini Hack contest.
Vote on your favorite animations before Dec. 3rd. We will give out MATLAB T-shirts to 10 lucky voters!
Tips: the more you vote, the higher your chance to win.
i=dsolve('Dy=-8*y+40*sin(8*t)','y(0)=5')
Warning: Support for character vector or string inputs will be
removed in a future release. Instead, use syms to declare
variables and replace inputs such as dsolve('Dy = -3*y') with syms
y(t); dsolve(diff(y,t) == -3*y). > In dsolve (line 126)
JAMEEL
JAMEEL
Posted on 24 Nov 2023 at 21:27

% Given data
x = [2.0, 3.0, 6.5, 8.0, 12, 15];
f = [14, 20, 17, 16, 23, 125];
% Construct the cubic spline
h = diff(x);
A = zeros(length(x)-2);
for i = 1:length(x)-2
A(i,i) = 2*h(i) + 2*h(i+1);
A(i,i+1) = h(i+1);
A(i+1,i) = h(i);
A(i+1,i+1) = 2*h(i) + h(i+1);
end
b = [6*(f(2)-f(1))/h(1) + 6*(f(3)-f(2))/h(2);
6*(f(4)-f(3))/h(3) + 6*(f(5)-f(4))/h(4)];
M = A\b;
% Evaluate the second derivative at data points
d2f_dx2 = zeros(length(x),1);
for i = 1:length(x)-2
d2f_dx2(i) = M(i);
d2f_dx2(i+1) = M(i) + h(i)*M(i+1);
d2f_dx2(i+2) = M(i) + 2*h(i)*M(i+1) + h(i)*h(i)*M(i+2);
end
% Display second derivatives at data points
disp('Second Derivatives at Data Points:');
disp(d2f_dx2);
Sanika Patil
Sanika Patil
Posted on 24 Nov 2023 at 9:22

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback Error while evaluating Button PrivateButtonPushedFcn.
help to solve this error in face recognition GUI
i've finished writing the code for my ~masterpiece~ and it doesn't run on the contest new entry page. it runs on matlab on my desktop and in the matlab live editor in my browser, but not where i really need it to. usually it'll draw the first frame the first time i run the code in a new window, but not any subsequent times. whether i hit "run" or "create animation", the screen grays out as it's supposed to, but then returns to normal without generating the first frame or animation.
i'm not getting a timeout warning or any error messages. i timed the code on my laptop and it takes about 100ish seconds to run and generate the animation the first time i run it before clearing everything from my workspace (and then it takes about twice as long each subsequent time, which makes me a bit nervous. can't figure out why this is the case at all!), which is well within the 255 second limit for the contest. as far as i know, the most computationally expensive function i'm using is patch(). i'm pretty close to the character limit, but i don't know if that's part of the problem.
i tried vectorizing some of the code instead of using for loops, which made the code run slightly slower. i tried using a nested function instead of using drawframe() and an auxiliary function, but that didn't help. i tried clearing all variables except f at the end of drawframe() to no avail. i tried using the close command at the start of drawframe(), with similar success. i updated chrome, closed a bunch of windows, tried safari, used my sister's laptop, all with no luck.
has anyone else had this or a similar problem? any advice?
thanks!
丰 年
丰 年
Posted on 23 Nov 2023 at 6:35

打开matlab 示例 提示错误,提示“系统找不到指定的文件”
I'm getting an error error "using tall/cellfun" while doing a project listed in mathworks "Denoise Speech Using Deep Learning Networks". I don't know how to fix this error pr why this error occured in the first place. Seeking explanation for this particuar error. If you know anuthing about it then please consider helping me below this post.
Elija
Elija
Posted on 20 Nov 2023 at 5:18

Hello, all!
This is my first post after just joining this discussion, so please forgive me and provide kind assistance if I have posted to the wrong subsection!
I have a good interest in learning sql server course and right now I am taking help from various platforms like https://www.coursera.org/ https://www.udemy.com/
Also I have a doubt that is it a good option to learn from platforms like this or I should go for some sql server online training . I have searched for the solution of my queries in various above platforms which helped me up to some extent only as it was not directly given by any expert or trainer.
Hoping in getting a quick response
Thankyou in advance.
柯

Posted on 20 Nov 2023 at 1:39

Hello, I want to use a solenoid valve to open and close the two-phase flow circuit, and I should use those elements to achieve it.
Adrian Segura
Adrian Segura
Posted on 19 Nov 2023 at 16:28

Hello, I am a student and I am working on a neural network for a line follower car and I would like you to recommend a tutorial to implement it in simulink.
a = 0; % lower limit
b = 1; % upper limit
exact_integral = log(2); % Exact integral value
f = @(x) 1/(1+(x.^2));
fprintf('Integration of x*sqrt(1-x^2) from %d to %d:\n\n', a, b);
% Initialize arrays to store data for the log-log plot
N_values = [];
relative_precision_simpson = [];
fprintf('%-20s %-20s %-20s\n', 'N', 'Extended Simpson', 'Relative Precision');
for N = 2:20
SN = extended_simpson(f, a, b, N);
relative_precision_simpson = [relative_precision_simpson, abs((SN - exact_integral)/exact_integral)];
fprintf('%-20d %-20e %-20e\n', N, SN, abs((SN - exact_integral)/exact_integral));
N_values = [N_values, N];
end
loglog(N_values, relative_precision_simpson, '-o');
xlabel('Number of Sub-intervals (N)');
ylabel('Relative Precision');
legend('Extended Simpson');
title('Log-log Plot of Relative Precision vs Number of Sub-intervals');
grid on;
function S2N = extended_simpson(func, a, b, n)
if n < 0
error('Negative n in extended_simpson');
elseif n == 0
S2N = (b - a) * (feval(func, a) + 4 * feval(func, (a + b) / 2) + feval(func, b)) / 6;
else
h = (b - a) / 2^n; % initial step size
x_vals = a:h:b; % partition points
S2N = feval(func, a) + feval(func, b);
for i = 1:(2^n - 1)
x = x_vals(i);
if mod(i,2) == 0
S2N = S2N + 4 * feval(func, x);
else
S2N = S2N + 2 * feval(func, x);
end
end
S2N = h / 3 * S2N;
end
end
The code above shows a upward trend for the Simpson's rule with the given function. However, it should show a downward trend for the relative precision. What could be the problem here?

Greetings great community I need help with 2D or 3D grid formation in MATLAB and how to assign charge particles on each cell that constitutes the entire grid

I think it would be a really great feature to be able to add an Alpha property to the basic "Line" class in MATLAB plots. I know that I have previously had to resort to using Patch to be able to plot semitransparent lines, but there are also so many other functions that rely on the "Line" class.
For example, if you want to make a scatter plot from a table with things specified into groups, you can use ScatterHistogram or gscatter but since gscatter uses the Line class, you can't adjust the marker transparency. So if you don't want the histograms, you are stuck with manually separating it and using scatter with hold on.
Vinay Ramesh
Vinay Ramesh
Posted on 14 Nov 2023 at 16:35

Dedicated to all Flipbook contest lovers! :D
Hello everyone! I'm new in MatLAB and i get confusing because i cannot run my program.
set(handles.ik5,'string',ik5);
set(handles.es5,'string',es5);
set(handles.el5,'string',el5);
-------------------------------------------------
Undefined variable "handles" or class "handles.ik5".
Error in Untitled (line 4)
set(handles.ik5,'string',ik5);
Hi, I'm in truble because I have two programs with the same variables and parameters. The main of the study is to change a value and plot the results. The problem is that I want them on the same plot but I use the same name for the variabes in the two different programs so when I use some function to join the figures togheter matlab resets the values obtained in the first program and runs only the second one.
Is there a method to avoid changing all the names of the variables in one of the two programs (because they have something like 500 lines)?