Math lab questions solve it

Write a generalized math lab program to print the following pattern first 5 the 4 4 then 3 3 3 then 2 2 2 2 then 1 1 1 1 1 (it look like triangle shape)

댓글 수: 12

Matt J
Matt J 2022년 8월 18일
I hope you realize that if someone answers your question, you will not be able to delete your post. Something to think about in case this is a homework question that your instructor might see.
Hakim
Hakim 2022년 8월 18일
No problem
Rik
Rik 2022년 8월 18일
For future questions:
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.
If you don't follow this advice, the chance of someone closing your question is substantial.
Hakim
Hakim 2022년 8월 18일
Rik I faced problem that's why I post it
Rik
Rik 2022년 8월 19일
There is no problem posting a question, but you see what happens.
What would happen if I gave you my email address as you requested? Will you follow the advice I gave you in my comment? Somehow I doubt it. I don't do private consulting, nor do most people here. Yair Altman is one of the few exceptions I'm aware of.
If you want to learn Matlab, you need to put in some effort. Follow the advice I gave you in the previous comment, and you will find most people here are willing to help you.
Hakim
Hakim 2022년 8월 19일
Plz give me your email address
Rik
Rik 2022년 8월 19일
Why don't you respond to what I ask in my comment?
What were you planning to send me? Anything relevant to this question can be posted here. I don't see why you would need to send me anything by email. You already asked me for my email address via the contact form. Repeating the request in a comment does nothing useful.
I will send some questions
Rik
Rik 2022년 8월 19일
If you ignore half of my comment, why should I respond to your comment?
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.
Rik
Rik 2022년 8월 19일
Come on. Read my comments. Stop sending me emails. If you want to show me a pdf, attach it to a comment or question.
If your English is not good enough to understand me, use something like Google Translate to translate it to your own language.
I'm not a private consultant. I will not give you my email address.
Please read the advice I gave you.
John D'Errico
John D'Errico 2022년 8월 19일
편집: John D'Errico 2022년 8월 19일
And this just one of many reasons why answering homework questions is just a flat out bad idea on Answers. The student thinks it is ok to pester you for help, in fact, even demand help, as @Hakim is now demanding that people provide their e-mail addresses.
Even offering simple help as Rik did is bad for Answers, because it helps to create a monster, and because it encourges other monsters to think Answers is a service where we wil do their homework.
Is this homework? Or possibly even more likely, this is a test question @Hakim wants to have answered, and thinks is being subtle by declaring it NOT homework. Obviously, as there is no alternative reason why such an easy question would be so important to be answered.
I'm sorry, but this question should have been closed immediately. I would even argue that we should close the question now, even with an accepted answer. But then I would have never answered the question.
Rik
Rik 2022년 8월 19일
@John D'Errico I'll close the question.
@Hakim, stop contacting me via email. If you provide any proof you've read and understood the links I provided I may respond. If you send me another request via the contact form I will contact Mathworks staff.

 채택된 답변

Rik
Rik 2022년 8월 18일

0 개 추천

I will not do your homework for you, but these pointers should help you.
doc for
FOR Repeat statements a specific number of times. The general form of a FOR statement is: FOR variable = expr, statement, ..., statement END The columns of the expression are stored one at a time in the variable and then the following statements, up to the END, are executed. The expression is often of the form X:Y, in which case its columns are simply scalars. Some examples (assume N has already been assigned a value). for R = 1:N for C = 1:N A(R,C) = 1/(R+C-1); end end Step S with increments of -0.1 for S = 1.0: -0.1: 0.0, do_some_task(S), end Set E to the unit N-vectors for E = eye(N), do_some_task(E), end Long loops are more memory efficient when the colon expression appears in the FOR statement since the index vector is never created. The BREAK statement can be used to terminate the loop prematurely. See also PARFOR, IF, WHILE, SWITCH, BREAK, CONTINUE, END, COLON. Documentation for for doc for
doc repmat % although you can do this part with a loop as well
REPMAT Replicate and tile an array. B = REPMAT(A,M,N) or B = REPMAT(A,[M,N]) creates a large matrix B consisting of an M-by-N tiling of copies of A. If A is a matrix, the size of B is [size(A,1)*M, size(A,2)*N]. B = REPMAT(A,N) creates an N-by-N tiling. B = REPMAT(A,P1,P2,...,Pn) or B = REPMAT(A,[P1,P2,...,Pn]) tiles the array A to produce an n-dimensional array B composed of copies of A. The size of B is [size(A,1)*P1, size(A,2)*P2, ..., size(A,n)*Pn]. If A is m-dimensional with m > n, an m-dimensional array B is returned. In this case, the size of B is [size(A,1)*P1, size(A,2)*P2, ..., size(A,n)*Pn, size(A, n+1), ..., size(A, m)]. REPMAT(A,M,N) when A is a scalar is commonly used to produce an M-by-N matrix filled with A's value and having A's CLASS. For certain values, you may achieve the same results using other functions. Namely, REPMAT(NAN,M,N) is the same as NAN(M,N) REPMAT(SINGLE(INF),M,N) is the same as INF(M,N,'single') REPMAT(INT8(0),M,N) is the same as ZEROS(M,N,'int8') REPMAT(UINT32(1),M,N) is the same as ONES(M,N,'uint32') REPMAT(EPS,M,N) is the same as EPS(ONES(M,N)) Example: repmat(magic(2), 2, 3) repmat(uint8(5), 2, 3) Class support for input A: float: double, single integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64 char, logical See also BSXFUN, MESHGRID, ONES, ZEROS, NAN, INF. Documentation for repmat doc repmat Other functions named repmat codistributed/repmat InputOutputModel/repmat tall/repmat gpuArray/repmat symfun/repmat
doc fprintf
FPRINTF Write formatted data to text file. FPRINTF(FID, FORMAT, A, ...) applies the FORMAT to all elements of array A and any additional array arguments in column order, and writes the data to a text file. FID is an integer file identifier. Obtain FID from FOPEN, or set it to 1 (for standard output, the screen) or 2 (standard error). FPRINTF uses the encoding scheme specified in the call to FOPEN. FPRINTF(FORMAT, A, ...) formats data and displays the results on the screen. COUNT = FPRINTF(...) returns the number of bytes that FPRINTF writes. FORMAT is a character vector that describes the format of the output fields, and can include combinations of the following: * Conversion specifications, which include a % character, a conversion character (such as d, i, o, u, x, f, e, g, c, or s), and optional flags, width, and precision fields. For more details, type "doc fprintf" at the command prompt. * Literal text to print. * Escape characters, including: \b Backspace '' Single quotation mark \f Form feed %% Percent character \n New line \\ Backslash \r Carriage return \xN Hexadecimal number N \t Horizontal tab \N Octal number N For most cases, \n is sufficient for a single line break. However, if you are creating a file for use with Microsoft Notepad, specify a combination of \r\n to move to a new line. Notes: If you apply an integer or text conversion to a numeric value that contains a fraction, MATLAB overrides the specified conversion, and uses %e. Numeric conversions print only the real component of complex numbers. Example: Create a text file called exp.txt containing a short table of the exponential function. x = 0:.1:1; y = [x; exp(x)]; fid = fopen('exp.txt','w'); fprintf(fid,'%6.2f %12.8f\n',y); fclose(fid); Examine the contents of exp.txt: type exp.txt MATLAB returns: 0.00 1.00000000 0.10 1.10517092 ... 1.00 2.71828183 See also FOPEN, FCLOSE, FSCANF, FREAD, FWRITE, SPRINTF, DISP. Documentation for fprintf doc fprintf Other functions named fprintf dlarray/fprintf icinterface/fprintf serial/fprintf gpuArray/fprintf

댓글 수: 7

Hakim
Hakim 2022년 8월 18일
This is not my home work. So Plz solve me with cide
@Hakim did you even try to use fprintf()? If not, you really need to learn how to use that function because it's used all the time. For example
fprintf('5\n44\n');
5 44
I'm sure you can figure out how to extend it down to 1. It's trivial.
Walter Roberson
Walter Roberson 2022년 8월 18일
This task is common to be given as an early assignment in MATLAB classes. It might not be homework for you but it is certainly homework for other people, and we are not going to post a solution.
This task is intended to be very basic. It can be done one character at a time knowing only how to write for loops, how to display a single character, and how to code the displaying of end of line. Or it can be done one line at a time knowing how to write for loops and how to store into an array and how to display an array.
Hakim
Hakim 2022년 8월 18일
Can you give me your email address
Walter Roberson
Walter Roberson 2022년 8월 18일
Image Analyst uses a public junk email address that anyone can read and which deletes all messages after one hour. He almost never looks there. So even if you managed to find the address, chances are slim that he will ever read the message.
I would be unlikely to respond to an email about this task, unless it would be to point you to resources to learn matlab.
I would suggest that for your learning purposes that you first implement the program in any procedural programming language that you are already comfortable with, and then figure out the closest matlab equivalent to each statement.
Hakim
Hakim 2022년 8월 18일
Plz give me your email before @
Walter Roberson
Walter Roberson 2022년 8월 18일
My email address before the @ is c6614770

추가 답변 (0개)

이 질문은 마감되었습니다.

질문:

2022년 8월 18일

마감:

Rik
2022년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by