Question

Use matlab and write script: Please use n = input('Enter the value of n :') not...

Use matlab and write script:

Please use n = input('Enter the value of n :') not the function command.

Consider the following equation

6a + 9b + 20c = n

The variables a, b, and c can be thought of as the number (non-negative integers) of 6’s, 9’s, and 20’s in n. Note that for a given n, there might be one, multiple, or no solutions for a, b, and c. For example,

n = 15 → a = 1 and b = 1 and c = 0

n = 16 → no solution

n = 24 → a = 4 and b = 0 and c = 0: a = 1 and b = 2 and c = 0

Write a Matlab script that asks the user for n and calculates the solutions of this equation, i.e. how many 6’s, 9’s, and 20’s fit in n. Show that this equation has exact solutions for n = 50, 51, 52, 53, 54, and 55 and list all the combinations of a, b, and c for each case.

Deliverables: Your Matlab script and its outputs with the given values of n.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clc
clear all
close all
n=input('Enter n: ');
sol=0;
flag=0;
for a=0:(n/6)
for b=0:(n/9)
for c=0:(n/20)
if((n-(6*a)-(9*b))/c==20)
sol=[a;b;c];
flag=1;
break;
end
if((n-(20*c)-(9*b))/a==6)
sol=[a;b;c];
flag=1;
break;
end
if((n-(6*a)-(20*c))/b==9)
sol=[a;b;c];
flag=1;
break;
end
end
end
end
if(flag==1)
disp('Solution is');
disp(sol);
else
disp('Solution does not exist');
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Use matlab and write script: Please use n = input('Enter the value of n :') not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4-6 on matlab 4. Write a program in a script file that determines the real roots...

    4-6 on matlab 4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...

  • Write a script that prompts the user to enter a value n (n > 6) that...

    Write a script that prompts the user to enter a value n (n > 6) that will generate an n element vector of random integers between 0 and 100 that will represent quiz grades. Then have the script calculate the average of the quizzes where the smallest grade is dropped. Then script will display the average of the quizzes along with the highest quiz grade. Given the following system of equations: 8s - 11t + 7u + 5v - w...

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • 5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j)...

    5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j) end fprintf('\n') % start a new line. end 5 (i) For ax2 + bxc 0, the value of x is given by 2a Write a MATLAB function quadrasol () that will have three inputs ( a,b, and c) and two outputs corresponding to the solutions of the equation. It may be more compact if you defined another variable 'd' for the term inside the...

  • Using MATLAB code only please! 4. Write a script which does the following (use a while...

    Using MATLAB code only please! 4. Write a script which does the following (use a while loop). a. Creates a random number b. Calculates the sum of random numbers selected, across all loop iterations c. Prints the number of random numbers (the number of loop iterations) which were required to add up to 20 (or more).

  • Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

    Please show in MATLAB code using if and else statements if necessary Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command....

  • Please use Matlab to solve and show your full codes Write a script file Ask the...

    Please use Matlab to solve and show your full codes Write a script file Ask the user to enter sides of a triangle: a, b, c Check to see if the sides are all greater than 0 If they are: Use the function (triangle) that you created in your last homework problem (HW#5 problemttF) to calculate the area. command Display the results on the screen using fprintf write the results to disk using the fprintf command. If any of the...

  • P2) Write a MATLAB function myLinReg Username that is defined below. Use the in-built MATLAB func...

    P2) Write a MATLAB function myLinReg Username that is defined below. Use the in-built MATLAB function sum( ) to ease your programming (you are NOT allowed to use polyfit() and polyval()). Test the output of this function with the results obtained by hand for P1. Submit printout of program and a screenshot of the command window showing the results for P1. function [coeffvec, r2]-myLinReg_Username (xi,yi) %Function file: myLinReg-Username .m Purpose : 8 To obtain the parameters of a L.S. linear...

  • MATLAB Question: Write a script for the problem pictured. Please send the script, not just the...

    MATLAB Question: Write a script for the problem pictured. Please send the script, not just the printout. Make sure your script allows you to input a value for n so when prompted, in the command window, user types n value. The n value should be the f_k if k ==1 .... Please also send print outs if you can. BELOW IS A SAMPLE ANSWER THAT DID NOT PUT THE INPUT SCRIPT NEEDED FOR THIS QUESTION TO BE CORRECT. YOU CAN...

  • 2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resis...

    2. [5pts] Write a MATLAB script that can calculate the equivalent resistance in a circuit that all electrical resistors are connected in parallel: . Print the title 'Equivalent Resistance for Resistors Connected in Parallel' on your output. . Check the size of vector resistor to see how many resistors in the circuit. .Check each individual resistance to see any 0 or negative resistance. If there is any, print message 'ERROR', then finish the program. . Otherwise, calculate the equivalent resistance...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT