Solution:
Matlab code is developed for calculating the sum using while loop. code is appended below.
clear all;
clc;
x=2;
y = my_fun(x);
disp('The value of y is');
disp(y);
-----------------------------------
Function definition
Code:
function y1 = my_fun(x1)
n=50;
sumx1 = 0;
k=1;
while(k<n+1)
sumx1 = sumx1 + x1^(2*k);
k=k+1;
end
y1 = sumx1
end
Results: results obtained for x=2
The value of y is
1.6902e+30
Problem# 3 1. (10 points) Write a Matlab function called my fun that takes, x as...
Repost pls show clear and correct codes in matlab..
Question 2. Write a MATLAB Function my-fun that takes as its input a vector of numeric values nums and returns a vector whose values are exactly/only the indicies of nums whose values are non- zero. You may not use any built-in MATLAB functions - i.e. find Sample call(s): CALL 1: my-fun( [8 05 0] ) \% would evaluate [1 3] CALL 2: my-fun ( [0 9 0 1 0] ) \%...
How will the function look in MATLAB? Write a function called plot_prop that takes an input value n. You need to plot a parabola i.e. a plot which ranges from a value to zero and then again from zero back to that value. Your parabola must be able to take any number (n) as an input. a) The line of the parabola is magenta and a solid line. b) The points of the parabola are starred. c) The X-axis is...
MATLAB Problem
HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...
This basic problem demonstrates the while-loop. (USE
MATLAB)
Write a Matlab function called steps that takes one scalar as an
input argument and returns two scalars as output arguments. If it
is called this way [n, d_left] = steps(d), then it sets n equal to
the minimum number of steps required to move from a distance of one
foot away from a wall to a distance less than d feet from the wall.
The first step is 1/2 foot. If...
This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice
This problem investigates how...
MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB
Use matlab please Write a function mydicegame that takes an input vector d of 5 numbers (representing a roll of 5 dice) and generates the following score s for each roll as an output: -50 points if all the dice are the same value -30 points if they are all consecutive values (e.g. 1 2 3 4 5 or 2 3 4 5 6) -5 points if two of the numbers are the same -10 points if 3 of the...
Write a matlab function called strip
Write a function called strip which takes in a single string s, and returns a version of s with all the spaces removed. The format of the output is specified in the following examples >> strip ('This is a test') This is a test >> strip ('Another test') Another test
Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...
Matlab Write a function called matrixsum that takes any matrix to calculate and return the sum of all matrix elements (this function must not use any array operations. It must instead use a for-loop.)