Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function with the following header: function [sorted bookshelfl my sort

ID: 3797784 • Letter: W

Question

Write a function with the following header: function [sorted bookshelfl my sort bookshelf(bookshelf) where bookshelf is a non-empty 2 x n cell array (you can assume than n 0) where each column represents one book. In each of these columns, the value in the rst row is a scalar of class double that represents the DDC number of the book (the rst three digits only), and the value in the second row is a non-empty row vector of class char that represents the title of the book. sorted bookshelf is a 2 xn cel array where each column represents one book using a format similar to the format used for the input parameter bookshelf. sorted should represent the same list of books as bookshelf, except that the books should be sorted by increasing DDc number. Books whose DDC number is set to NaN should come last. If two more books share the same DDc number, then they should be ordered in the alphabetical order of their title. This rule also applies when two or more books have their DDC numbers set to NaN You are allowed to use Matlab's built-in function sort for this problem. This built-in function can sort in increasing order row vectors of class double. It can also sort in alphabetical order character strings placed in a 1 m cell array Note that the actual DDC system speci es that if two or more books share the same DDC number, then they should be ordered in the alphabetical order of their author's last name. In this question, we use the book's title instead of the author's last name to sort books which have the same DDC number. Test cases: bookshelf (422, 851, 825, 825, 'where words come from Poesie', 'Programming is useful', 'Go B9!') sorted bookshelf my sort bookshelf(bookshelf) sorted bookshelf 2x4 cell array [42211825] [825] [851] useful 'Poesie where words come from Go B9!' 'Programming is bookshelf 1,1) NaN bookshelff2,1) Discard' sorted bookshelf my sont bookshelf(bookshelf) sorted bookshelf 2x4 cell array 'Go B9!' 'Programming is useful' 'Poesie' 'Discard

Explanation / Answer

% Logistics Map % Classic chaos example. Plots semi-stable values of % x(n+1) = r*x(n)*(1-x(n)) as r increases to 4. % % Michael Hanchak, Dayton OH, USA, 2011 clear scale = 10000; % determines the level of rounding maxpoints = 200; % determines maximum values to plot N = 3000; % number of "r" values to simulate a = 2.0; % starting value of "r" b = 4; % final value of "r"... anything higher diverges. rs = linspace(a,b,N); % vector of "r" values M = 500; % number of iterations of logistics equation % Loop through the "r" values for j = 1:length(rs) r=rs(j); % get current "r" x=zeros(M,1); % allocate memory x(1) = 0.5; % initial condition (can be anything from 0 to 1) for i = 2:M, % iterate x(i) = r*x(i-1)*(1-x(i-1)); end % only save those unique, semi-stable values out{j} = unique(round(scale*x(end-maxpoints:end))); end % Rearrange cell array into a large n-by-2 vector for plotting data = []; for k = 1:length(rs) n = length(out{k}); data = [data; rs(k)*ones(n,1),out{k}]; end % Plot the data figure(97);clf h=plot(data(:,1),data(:,2)/scale,'k.'); set(h,'markersize',1) axis tight set(gca,'units','normalized','position',[0 0 1 1]) set(gcf,'color','white') axis off

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote