Plotting a solution Function Graph

I need the graph of this function. I tried to write MATLAB codes. But i couldn't manage. Please help me.
From now, thanks.

11 Comments

This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
I know MATLAB essentials but i couldn't write piecewise function MATLAB codes. Please help.
See piecewise()
Note; in order to use matlabFunction() with piecewise(), you must tell matlabFunction() to write to a file.
I know to use piecewise function but here, the number of intervals are very very much. So I couldn't manage to write codes using loops and conditions.
Please help.
Torsten
Torsten on 31 May 2021
Edited: Torsten on 31 May 2021
If someone might try to program your function:
I guess there is a mistake in the definition of phi(i). A product of mu*(theta(m+1)-theta(m)) is running from
m = i to m = i-1. This would mean that the product is empty and always has a value of 1 per definition.
My guess is that it should run from m = k to m = i-1
Dear Torsten,
It is not mu*(theta(m+1)-theta(m))
but
mu(theta(m+1)-theta(m))
i.e. this is the value of function mu at (theta(m+1)-theta(m)) .
I corrected that mistake. Please help.
here, the number of intervals are very very much. So I couldn't manage to write codes using loops and conditions.
Oh?
n = 100;
syms x
y = sym(0);
for k = 1 : n
y = y + piecewise(x <= k & x < k + 1, x/k, 0);
end
y
y = 
Loops and conditions seem to generally work fine to build piecewise expressions.
(Building the expression in this particular manner slows down as it goes; you can reduce that by breaking the task up into pieces. For example, you could create the expression for 1 to 5, and 5 to 9, 10 to 14, 15 to 19, 20 to 24, and add those together. Do the same thing for three other groups of 5. Then at the end add the four groups of 25. This kind of decomposition of the additions into sizes that are prime factors reduces the total work required to merge the conditions into their proper order.
Dear Friend Walter;
We can chose n=10.
And... ?
n = 10;
syms x
y = sym(0);
for k = 1 : n
y = y + piecewise(x <= k & x < k + 1, x/k, 0);
end
y
y = 
I do not see why you could not use loops and piecewise() to build up expressions ?
Dear Walter, can you help me to write for plotting codes of the function using loops? Because, i couldn't manage.
I do not see your code attempt posted? This question has longer formulas, and the volunteers are not going to bother typing everything in from scratch to show you the resulting code just to prove that it can be done.

Sign in to comment.

Answers (0)

Products

Release

R2020a

Asked:

on 30 May 2021

Commented:

on 28 Jun 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!