Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:31:12+00:00 2026-05-26T02:31:12+00:00

How do I plot the value of Approximation – Answer as s varies in

  • 0

How do I plot the value of Approximation - Answer as s varies in the code below? If you look at my code below, you can see the method I used (I put it in a separate file).

However, it does not show me a graph from 1 to 1000. Instead the graph is from 999 to 1001 and does not have any points on it.

for s = 1:1000
    error = LaplaceTransform(s,5) - (antiderivative(1,s)-antiderivative(0,s));
end
plot(s,error);
title('Accuracy of Approximation');
xlabel('s');
ylabel('Approximation - Exact Answer');

The functions used:

function g = LaplaceTransform(s,N);
% define function parameters
a=0; 
b=1;
h=(b-a)/N;
x = 0:h:1;
% define function
g = ff(x).*exp(-s*x);

% compute the exact answer of the integral
exact_answer=antiderivative(b,s)-antiderivative(a,s)
% compute the composite trapezoid sum
If=0;
for i=1:(N-1)
    If=If+g(i).*h;
end;
If=If+g(1).*h/2+g(N).*h/2;
If

with

function fx=ff(x)
fx=x;

and

function fx=antiderivative(x,s);
fx= (-exp(-s*x)*(s*x+1))/(s^2);

Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:31:12+00:00Added an answer on May 26, 2026 at 2:31 am

    The following

    for s = 1:1000
        error = LaplaceTransform(s,5) - (antiderivative(1,s)-antiderivative(0,s));
    end
    plot(s,error);
    

    already has several issues. The two main ones are that error is getting overwritten at each iteration, as @Amro has pointed out, and that s, your loop variable, is a scalar.

    Thus, you need to write

    difference = zeros(1000,1); %# preassignment is good for you
    for s = 1:1000
        difference(s) = LaplaceTransform(s,5) - (antiderivative(1,s)-antiderivative(0,s));
    end
    plot(1:1000,difference);
    

    There is another error in the LaplaceTransform function

    function g = LaplaceTransform(s,N);
    [...]
    g = ff(x).*exp(-s*x); %# g is an array
    
    [...]
    If %# If is calculated, but not returned.
    

    I assume you want to write

    function If = LaplaceTransform(s,N);
    

    instead, because otherwise, you try to assign the array g to the scalar difference(s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plot (sample code pasted below) that I am trying to add
How can I render the value of points in a plot in the plot
I have below a code that will plot a sphere, it's proportions are defined
I have plotted an histogram for the value 'Q' in my code below. I
Is there a way to plot multiple data for the same value x? For
How do I make a plot in R so that the value of a
I'm having a function to plot a graph. I'm having value zero, it is
On this code: def plot(div_name = , series , options = {} ) I'm
How do I configure a ggplot2 step plot so that when the value being
Below is a plot which should contain lines of different types (solid and dashed)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.